General Actions:
| Allows translating Strings into different languages |
| Type | JAR |
| Developed by | |
| License | GNU Lesser General Public License 2.1 |
| Bundled With | XWiki Enterprise, XWiki Enterprise Manager |
| Compatibility | Since 4.3M2 |
Table of contents
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 components (or any Java code in general) to be translated into different languages.
You can insert a translation in a content using the translation macro as follow:
See the Translation Macro documentation for more details.
The identifier of the Localization Script Service is localization.
A translation corresponding to a key can be obtained by calling:
The printable translation of a defined property is obtained by calling:
As with the old MessageTool, parametrized translations can be obtained with:
where parameters is a list of parameter values. The format of the translation is the one accepted by the MessageFormat class.
It's also possible to choose the syntax in which the translation message is going to be rendered using:
the default being plain/1.0.
It's possible to add on demand translation bundles for the current execution by indicating their type and identifier like in:
[since 5.0M1] Getting the current Locale:
As with any other Component, you can either declare a dependency on the Localization tool in your Component, or you can request the Component from the Component Manager. The dependency should usually look like:
The API is located in org.xwiki.localization.LocalizationManager in the xwiki-platform-core/xwiki-platform-localization/xwiki-platform-localization-api 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.
It's possible to mark a document as a Document Resource Bundle by adding a XWiki.TranslationDocumentClass XObject to this document.
A jar (installed extension or core extension) can come with its own translations bundle. For that all is needed is to name it ApplicationResources.properties for the default language and ApplicationResources_<locale>.properties (for example ApplicationResources_pt_BR.properties) for its translations and put them in the default package (i.e. root of your JAR). It will be automaticlally registered at startup for core extensions and when installed for installed extension (it will also be unregistered automatically if the jar extension is uninstalled).