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 :

  • - Default language
  • - French
  • - French (France)
  • - French (Canada)
  • - 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>
File's location
Key's structure portal.<subsystem>.<key>


File name <plugin>
File location<plugin>.resources
Key structure <plugin>.<key>

Module of a Plugin

File's name <module>
File's location<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

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

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 );