Localization Plugin

This application is bundled with:
  • XWiki Enteprise
Plugin developed by the XWiki Development Team.
This plugin cannot currently be downloaded separately.

Localization Plugin

This is not a plugin, but a component in the new component-oriented architecture of XWiki.
Warning: This component has not been released yet; it will be part of XWiki 1.7 M1.
The Localization Component is an efficient and flexible replacement of the old MessageTool class, which eases the deployment of XWiki applications.

Localization here refers to translation; see the Wikipedia article about internationalization and localization for more details. In summary, this component allows applications and plugins to be translated into different languages.

Features

  • Efficient implementation by making intensive use of caching.
  • Pluggable Bundle types, allowing developers to create and use new types of resources. At the moment bundles defined in wiki documents and in .properties files are supported. See http://java.sun.com/docs/books/tutorial/i18n/resbundle/index.html for more details on this type of files.
  • Document bundles can be dynamically pulled in by user code (application documents, sheets, templates, java classes). This allows applications and plugins/components to include their own translation documents without requiring additional configuration, and without bloating ApplicationResources.properties.
  • Powerful parametrized translations, as supported by the java MessageFormat class.

Usage

From velocity

The variable that gives access to the localization component is $l10n. A translation bundle is pulled by calling the function:

$l10n.use(hint, bundleLocation)
where hint is a String identifying the type of bundle to be used. The localization component currently supports bundles defined in Wiki documents, for which the hint is "document":
$l10n.use("document", "The.Document")
and bundles defines in .properties files, for which the hint is "resource":
$l10n.use("resource", "theBundle")

The translation of a defined property is obtained by calling

$l10n.get(key)
As with the old MessageTool, parametrized translations can be obtained with:
$l10n.get(key, parameters)
where parameters is a list of parameter values. The format of the translation is the one accepted by the MessageFormat class.

From Java

As with any other component, you can either declare a dependency on the localization tool in your components.xml file, and the component manager will inject a reference in your objects, or you can request the component from the component manager. The dependency should usually look like:

<requirement>
  <role>org.xwiki.localization.LocalizationManager</role>
</requirement>

The API is located in org.xwiki.localization.LocalizationManager in the platform/core/xwiki-localization module. The ROLE (which is used for requesting the localization component from the component manager) is the name of this interface, org.xwiki.localization.LocalizationManager.

Tags:
Created by Sergiu Dumitriu on 2008/10/14 20:54
Last modified by Sergiu Dumitriu on 2008/10/16 17:09

This wiki is licensed under a Creative Commons license
2.2.1.27354