What is the best practice for locales and multiple language support?

F_Schmidt :

I want to have multiple languages in my program. The java Locale class has some locales for example Locale.GERMAN, Locale.ENGLISH and so on. But I need additional locales for example spanish etc.

How can I store them and use them properly? What is the best practice?

Should I create some kind of LanguageHandler that stores all required locales in an array? Any experiences and practices on that topic?

Edit: The application is for Desktop and written in Java.

Rupesh :

Get a list of all the supported locales:

You can use Locale spanish = new Locale("es", "ES"); to use Spanish in Spain locale.

How can I store them and use them properly? What is the best practice?

As per my understanding you don't have to store a master list of supported locales. You can use them as you go. By defining locale as mentioned above will help you load the ResourceBundles by passing locale objects but then you would need to create ResourceBundles for each locale you want to use in your application.

For example for some resources in different language you might want to consider translations.

Further reading on how to use locale to init resourceBundle.

http://tutorials.jenkov.com/java-internationalization/resourcebundle.html

https://mkyong.com/java/java-resourcebundle-example/

How to load a resource bundle from a file resource in Java?

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=408983&siteId=1