Internationalization (i18n)

Resource localization

The mechanism of localisation for labels and messages is based on the recommendations and tools offered by the Java API. The files containing the localized resources are text "properties" files with a suffix indicating the language and possibly the country. Those files are loaded by the class ResourceBundle that will choose according to the locale the right localized strings. Here are suffix rules :

  • myplugin_messages.properties - Default language
  • myplugin_messages_fr.properties - French
  • myplugin_messages_fr_FR.properties - French (France)
  • myplugin_messages_fr_CA.properties - French (Canada)
  • myplugin_messages_en_US.properties - English (United States)
  • ...

Rules for message bundles

To find in which file is located a resource key, bundle's file name and location should respect strictly the following rules depending on the component type (core, plugin, module of a plugin) :

Subsystem of the core

File's name <sous-systeme>_messages.properties
File's location fr.paris.lutece.portal.resources
Key's structure portal.<subsystem>.<key>

Plugin

File name <plugin>_messages.properties
File location fr.paris.lutece.portal.<plugin>.resources
Key structure <plugin>.<key>

Module of a Plugin

File's name <module>_messages.properties
File's location fr.paris.lutece.portal.<plugin>.modules.<module>.resources
Key's structure module.<plugin>.<module>.<key>

Localizing templates

Templates are localized on load by the method AppTemplateService.getTemplate( ... , Locale locale , ... ). Keys should be embraced and prefixed by #i18n.

Templates keys should respect this structure :

Bundle's prefix Template's name Name of the label or input
portal.<subsystem>.
<plugin>
module.<plugin>.<module>.
manage_myobjects
create_myobject
titleObjectList
labelName
buttonCreate

<h2>#i18n{document.create_document.title} « ${document_type} »</h2>
<div class="highlight-box">
    <p>
         <label for="document_title">#i18n{document.create_document.labelDocumentTitle}* : </label>
         <input type="text" name="document_title" size="80" maxlength="255"/> 
         #i18n{document.create_document.helpDocumentTitle}
    </p>
 ...                      

Localization in Java code

In the code, the I18nService can be used to localize strings according the current locale. NB : To respect coding rules, keys must be declared as constants as follows :

private static final PROPERTY_MESSAGE_MYMESSAGE = "myplugin.myMessage";

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