Versions Compared

Key

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

...

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

Translating Text In Mini-Language

The process is similar in Mini-Language, but the syntax is slightly different:

Code Block
xml
xml

<property-to-field resource="CommonUiLabels" property="CommonAddNew" field="addNew"/>
<log level="info" message="${addNew}"/>

where resource is the name of the UI label file (extension optional) and field is the name of the variable that will contain the translated text.

Translating Text In Java

Translating text in Java is accomplished by using the org.ofbiz.base.UtilProperties class. Here is an example:

Code Block
java
java

public static Map<String, Object> myJavaService(DispatchContext ctx, Map<String, ?> context) {
    Locale locale = (Locale) context.get("locale");
    try {
        // Do something risky
    } catch (Exception e) {
        return ServiceUtil.returnError(UtilProperties.getMessage(MyUiLabels, "RiskyErrorMessage", locale));
    }
    ...
}