Temporary display of text (not dates) in another language

I am trying to display some message on the screen in another language (but keeping the dates in the default language, uk_eng), depending on what the user is looking at the screen. Being just a temporary installation, I was wondering what is the best way to do this in Java.

+4
source share
2 answers

You may have message packages for each locale. Download them and display them accordingly when you identify the user language.

Example: http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/int.html

You can download them in a web application, for example, http://www.devsphere.com/mapping/docs/guide/internat.html

+3
source

If I see the problem well, you want to display messages using MessageFormat as follows:

  Object[] arguments = { new Integer(7), new Date(System.currentTimeMillis()), "a disturbance in the Force" }; String result = MessageFormat.format( "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.", arguments); 

(Example from javadoc)

I checked the source of MessageFormat , and I see that getLocale() is common to the whole message. You cannot make a separate parameter for a parameter.

Why don't you make a parameter with the most formatted date string? Like this:

  Object[] arguments = { new SimpleDateFormat("yyyyy.MMMMM.dd GGG hh:mm aaa", Locale.UK).format(new Date()) }; String result = MessageFormat.format( "This is the date format which I always want independently of the locale: {1} ", arguments); 

The first parameter of the format methods may come from localized property files.

0
source

All Articles