Mar 7, 2018 5:40:12 PM seb leridon avatar   1047

Internationalization (i18n)


Principles of resource location

The mechanism for locating labels and messages is based on the recommendations and tools offered by the Java API. Files containing the localized text resources are files " properties " having a suffix specifying the language and possibly the country.

The reading of the files is carried out by the class ResourceBundle which will choose according to the locale (variable representing a localization based on a language and a country) among the following files for example:

  • myplugin_messages.properties - default language
  • myplugin_messages_fr.properties - french
  • myplugin_messages_fr_FR.properties - french (France)
  • myplugin_messages_en_CA.properties - French (Canada)
  • myplugin_messages_en_US.properties - English (United States)
  • ...

File Rules

So that Lutece can determine which file to search for a key, the name and location of the resource files are subject to the following rules according to the type of component (kernel element, plugin or module of a plugin):

Kernel Subsystem
File Name <sous-systeme> _messages.properties
File Location fr.paris.lutece.portal.resources
Construction of the key portal.<sous-systeme> .<key>
Plugin
File Name <plugin> _messages.properties
File Location fr.paris.lutece.portal.<plugin> .resources
Building the key <plugin> .<key>
Module of a Plugin
File names <module> _messages.properties
File Location fr.paris.lutece.portal.<plugin> .modules.<module> .resources
Building the key module.<plugin> .<module> .<key>

Localization of templates

Templates are automatically located when they are loaded by the method AppTemplateService.getTemplate (..., local local, ...) . The keys to locate are indicated by the prefix # i18n followed by the key surrounded by parentheses.

The key structure is as follows:

Bundle localization prefix Template name Label name (label, title, button)

portal . [subsystem > . < plugin > module.<plugin> .<module,gt;. | manage_myobjectscreate_myobject | titleObjectListlabelNamebuttonCreate |

[Lt; h2 > # i18n {document.create_document.title} $ {document_type} < / h2 >
     < div class = " form-group " >
     [Lt; p >
          < label for = " document_title " [# i18n {document.create_document.labelDocumentTitle} *: [</label >
          < input type = " text " name = " document_title " size = " 80 " maxlength = " 255 " / >
          < span class = " help-block " [Gt; # i18n {document.create_document.helpDocumentTitle} < / span >
     [Lt; / p >
...

Labels i18n with parameters New LUTECE v5.0

It is possible from Lutece v5 to pass parameters to an i18n label using the pattern of the Java MessageFormat class in the myplugin_messages.properties resource file:

mykey.message = My message using 2 arguments: {0} and {1}

Warning ! Bookmarks in templates have a different syntax. the # i18n {" key " } is replaced by $ {i18n (" key ", arg1, ...)} as follows

$ {i18n (" myplugin.mykey.message ", argument1, argument2)}

Localization in Java code

In Java code, use the I18nService service for locate a key based on the current locale. NB: The values ​​of the keys must be declared in constants as in the example below.

private static final PROPERTY_MESSAGE_MYMESSAGE = " myplugin.myMessage [quot ;;

     ...
     String strLocalizedMessage = I18nService.getLocalizedString (PROPERTY_MESSAGE_MYMESSAGE, locale);
     ...

Value overload i18n New LUTECE v5.0

The default values ​​of the i18n keys are overloaded in files placed under / WEB-INF / conf / override / and respecting the same tree.