Java EE i18n and default project structure

I'm Python Django devel

I want to try a little Java.

In django, I used my translation as follows:

from django.utils.translation import ugettext_lazy as _

and then, if the translation is specified in the .po file in the locale / en / django.po file

_("hello world")

Question 1: Is there a similar thing in Java?

I found those:

but not one of them is what I'm looking for

I did as in the example

import java.util.ResourceBundle;
import java.util.MissingResourceException;

public class i18n {
    private static ResourceBundle myResources = ResourceBundle.getBundle("messages");

    public static String _ (String originalStr) {
        try {
            return myResources.getString(originalStr);
        } catch (MissingResourceException e) {
            return originalStr;
        }
    }

}

And later

import static i18n._;

Question 2: But where to put the messages.properties file?

  • I would like to have a separate locale directory with these files.
  • translations of the entire package and subpackages

    • locale / messages _en_US.properties
    • locale / messages _en_UK.properties
    • locale / messages _en_AU.properties
    • etc.

Question 3: This exception catching part seems to be down, do you know why?

4: JavaEE i18n?

, java EE , i18 , , java, . , , . Google Wave Protocol, .

5: JavaEE ?

-, , , . , . . , sql- , WTF...

+5
1

; . , .

, , , . , JSTL bundle; JSF loadBundle. .

...

ResourceBundle.getBundle , , , . WAR, JAR WEB-INF/lib WEB-INF/classes.

, ...

 /WEB-INF/classes/locale/messages.properties
 /WEB-INF/classes/locale/messages_fr.properties
 /WEB-INF/classes/locale/messages_de.properties

... , Locale :

ResourceBundle.getBundle("locale.messages", locale);

:

//BUG! this loads the properties file for the server default locale only!
private static ResourceBundle myResources = ResourceBundle.getBundle("messages");

. (, IDE).


, root messages.properties .

, . , , - - .

+11

All Articles