What is the best practice for implementing i18n in java?

What is the best practice for implementing i18n using java?

+6
java internationalization
source share
4 answers

You can use ResourceBundle.getBundle( name ) , which returns the correct set according to the user's locale and receives specific messages.

How the ResouceBundle class works, try downloading a package (usually a .properties file) with localized messages. For example, you can:

 messages_en.properties ----- greeting = "Hello " 

and

 messages_es.properties ----- greeting = "Hola " 

and use it as follows.

 ... void main( ... . { ResourceBundle bundle = ResourceBundle.getBundle( "messages", userLocale ); System.out.println( bundle.getString("greeting" ) + " Steve " ); } 

And he will print

 Hello Steve 

if the user language is English (ru) and

 Hola Steve 

if user language is spanish (es)

The ResouceBundle.getBundle () method not only downloads .properties files, if available, it can also load a class, which in turn can load a message from the database.

See also:

Resourcebundle

Internationalization Brief Introduction

+13
source share

Java tutorials have Internationalization . It covers the basic functions of a language for internationalization.

+3
source share

I would recommend looking at ResourceBundles.

This is a tricky question, because if you have a database, you will want to use it too.

+1
source share

This is basically a domain issue. If you are on the Internet, most of the main frameworks will provide a path for I18N (in Spring, this works with .properties and taglibs files ).

In desktop applications, on the contrary, resource deployment can be an interesting option. The Spring application framework goes even further and allows you to fully customize Swing components (buttons, shortcuts, ...) from configuration files. With this, you can set the colors and borders of the components, as well as their texts.

+1
source share

All Articles