Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Text Translation

OFBiz externalizes text presented to the user by keeping it in UI label files. Three file formats are supported:

  1. *.properties file that contains the text in key=value format, one file per locale
  2. *.xml file using the Java property XML file format, one file per locale
  3. *xml file using the OFBiz property XML file format, one file for all locales

All new OFBiz development uses the OFBiz XML file format. This format is preferred because it is easy to edit using Unicode languages, and it also makes it easier to notice missing translations.

Translating Text In The Screen Widgets And Freemarker Templates

Before the translated text can be used in a web page, the appropriate UI label file must be loaded into memory using the screen widget actions element:

Code Block
xml
xml

<actions>
    <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
</actions>

where resource is the name of the UI label file (extension optional) and map-name is the name of the Map that will contain the contents of the UI label file. The keys in the file become the Map keys.

Here is an example of translated text in CommonUiLabels.xml:

Code Block
xml
xml

<property key="CommonAddNew">
    <value xml:lang="ar">إضافة الجديد</value>
    <value xml:lang="de">Neu hinzufügen</value>
    <value xml:lang="en">Add New</value>
    <value xml:lang="es">Crear nuevo</value>
    <value xml:lang="fr">Ajouter un nouveau</value>
    <value xml:lang="it">Aggiungi nuovo</value>
    <value xml:lang="nl">Voeg een nieuwe toe</value>
    <value xml:lang="pt">Adicionar Novo</value>
    <value xml:lang="ro">Adauga Nou</value>
    <value xml:lang="ru">Добавить новый</value>
    <value xml:lang="th">เพิ่มใหม่</value>
    <value xml:lang="zh">新建</value>
    <value xml:lang="zh_CN">添加新的</value>
</property>

If we want to display this text, we simply reference it using String expansion:

Code Block
xml
xml

<!-- Screen widget -->
<container style="h1"><label text="${uiLabelMap.CommonAddNew}"/></container>
Code Block
xml
xml

<!-- Freemarker template -->
<h1>${uiLabelMap.CommonAddNew}</h1>

The text will be translated into the user's locale.