Localization Component

Last modified by Vincent Massol on 2024/11/19 16:12

 XWiki
 Requirements
 Completed
 

Description

The localization tool provides translations to java code, by using it as any other component, and to velocity, by placing a $msg variable in the velocity context.

API methods:

  • $msg.useDocumentBundle("Some.Document") - pulls a wiki document bundle in the current execution context. It will be available until the current request completes. Useful for wiki applications.
  • $msg.useFileBundle("path/to/Resources") - pulls a file bundle in the current execution context, actually a resource bundle like ApplicationResources.properties. It will be available until the current request completes. Useful for plugins/components.
  • $msg.get("key") - Works like the already existing method.
  • $msg.get("key", ["param1" ...]) - Works like the already existing method.

Besides the pulled bundles, the tool also uses:

  • a list of global document bundles, configured in XWikiPreferences
  • a static list of document bundles configured in components.xml
  • a static list of file bundles configured in components,xml

The order in which the tool searches for a translation is:

  1. pulled document bundles, in the order of their call.
  2. pulled file bundles, in the order of their call.
  3. global document bundles
  4. static document bundles
  5. static file bundles

Execution details and improvements over the current message tool:

  • singleton instance that relies on the execution context to store the lists of pulled bundles and to get the current language, instead of per-request instances
  • all loaded bundles are cached for all further request, instead of only for the current request
  • cached bundles are invalidated using the observation mechanism, instead of keeping a list of modification dates
  • bundles are loaded only when really needed, i.e. when a request for a key was not found in the previous bundles
  • only the bundle in the current context language is loaded (same as now)
  • for each language, the bundle inherits the default language definitions, instead of loading two different bundles and searching them in order
  • the default language is the one configured in the wiki (same as now)

 

Get Connected