internationalization - Java EE i18n and default project structure -


I'm developing Python DJGengo

I want to make a little effort to Java

I used to translate myself into the DEGENGO because it happens as follows: django.utils.translation import from ugettext_lazy _ _

And then if the translation

  _ ("Hello World")   

Question 1: Is there any such thing in which the locale / N / Is specified. Java?

I have found them:

  • There is no one I am looking for

    I did as an example

      import java.util.ResourceBundle; Import java.util.MissingResourceException; Public Class i18n {Personal Stable Resource Bundle myResources = ResourceBundle.getBundle ("Message"); Public Static String _ (String Original STR) Return {try {myResources.getString (Original STR); } Grip (missing RSOS Exception E) {Return Original STR; }}}   

    and later

      Fixed I18n._; Import;   

    Question 2: But where do you keep messages? Property file?

    • I have to keep a separate locale directory with those files.
    • Translation from entire package and sub-package

      • Locale / Message_en.properties
      • Locale / Message_n_uk Properties
      • Locale / Message_AnaAproporties
      • More ...

        Question 3: Exceptionist This part is not working, do you know why?

        Question 4: What is the standard standard for i18n?

        I thought that there should be a standardized app directory layout, i18 and war directory contents in Java EE, but for a few days to fool with Java I find it very chaotic. Therefore, every sample open source code I am getting on the internet is completely different. Starting with the Google Wave Protocol Project, the sample is ending with a small application.

        Question 5: Are Jawaii Coding Philosophy or Best Practices?

        I found but the developers do not care about it. Test placements, the same thing everybody places them in different templates, arguments like SQL queries in templates, WTF ...

        There is no right place to place resource files; This is generally a decision for the app developer, by putting all the files in a standard location, there can not be any sense in all architectures, so the specification connects unnecessary obstacles.

        In order to load and reference bundles of resources, it may have an effect on which settings you are using. For example, in a JSTL application, you can use tags; In a JSF application you can use tags. Other view technologies can define their own mechanisms.

        In general ...

        Loads resources from the classpath, so if you want to use a directory, then this or her parents should have one application In a war, on the other side, the bundles must be in a JAR file in the WEB-INF / lib directory or in the WEB-INF / classes directory.

        Then, for the bundle set ... / WEB-INF / class / link / message. Properties / WEB-INF / Classes / Local / Message_Frafficies / Web-NF / Classes /locale/messages_de.properties

        ... You will load the bundle by receiving the request: < Pre> ResourceBundle.getBundle ("locale.messages", Locale);


        There is a flaw in assigning a bundle to a static variable:

          // bug! This only loads the properties file for the server default locale! Personal Static ResourceBundle myResources = ResourceBundle.getBundle ("Message");   

        You need to get the user's location. A stable assignment would be suitable in client applications (like IDE).


        Note that this is usually a good idea to provide a root messages.properties base file as a fallback for the unsupported locale.

        As an ordinary localization on one side, the approach to use the original string as a key would be just fine if the key was unique to the bundle. Otherwise, it would be contradictory in cases where there were similar source strings which were translated separately due to the context.

  • Comments

    Popular posts from this blog

    qt - switch/case statement in C++ with a QString type -

    python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

    Python's equivalent for Ruby's define_method? -