Skip Navigation

Preparing Your Plug-in for Internationalization

Before you begin:

  • Your plug-in project must have text labels that you want to translate and an Activator class.

  • Add the com.sabre.edge.platform.core.nls dependency to your plug-in project using Eclipse.

Creating the Messages Class and Properties Files

  1. In Package Explorer, right-click the package name that you wish to translate. From the menu, choose Add > New Class.

  2. If the Package field is not populated, type the package name.

  3. In the Name field, type Messages. This is your Java class.

  4. In the Superclass field, extend com.sabre.edge.platform.core.nls.EdgeNLS.

  5. Be sure to select the following check boxes:

    • Constructor from superclass

    • Inherit abstract methods

  1. Click Finish.

Eclipse automatically generates Java code and displays the code in the Messages.java file in a Java editor.

  1. In the Java editor, make the following modifications to the code. The sample code is shown below.

    • Do not instantiate the Messages class.

    • Define all text that the Java code uses as public static String fields. The use of static strings from Messages initializes the messages in the proper language.

    • In the code, add one String field for every message that you want to translate. In another step, you will add the String fields to the English language messages.properties file and to all of your language versions of the messages_XX.properties files.

    • At the end of the file, initialize the messages as a static code call.

public class Messages extends EdgeNLS
{
    private static final String MESSAGES_FILE_NAME = "messages";

    private Messages()
    {
        // do not instantiate
    }
    public static String label_one;
    public static String label_two;

    static
    {
        initializeMessages(MESSAGES_FILE_NAME, Messages.class);
    }
}

 

  1. Prepare the following message properties files in ASCII format:

    • Create one file with the name messages.properties in English.

    • Create one messages_XX.properties file for all languages that you want to support.

  1. Inthe messages_XX.properties file name, substitute the following for XX:

        de for German

        es for Spanish

        fr for French

        it for Italian

        jp for Japanese

        pt for Portguese

        ru for Russian

  1. In the message properties files, add the string fields and their values in each language that you are supporting. Use the following syntax:

        key=value

        Where key corresponds to a field in your messages and Java files.

  1. In the message properties files, replace local characters with hexadecimal code. Use the following notation:

        \uXXXX

        Where XXXX is the code for the character in hexadecimal format.

You can use the native2ascii Java program to automatically convert a file with native-encoded characters to a file with the characters encoded in Unicode.

In the following sample files, the key is the label and the value is the text.

Fields in the Sample messages.properties File

label_one=Last Name

label_two=Time Format

Fields in the Sample messages_es.properties File

label_one=Apellido

label_two=Formato de hora

  1. In Messages.java, add the following code to access all the String fields in the messages.properties files.

label1.setText(Messages.label_one);

  1. On your local drive, create a source folder for internationalization resources. Common practice is to name the folder resources. Place the message properties files into the resources folder. This folder must also be created as Source Folder in Eclipse.

  2. Using Eclipse, add the resources folder to your sources in the build.properties file.

Localizing the XML Files

If your plugin.xml file defines labels or text that appears on the Sabre Red 360 GUI, localize the XML files.

  1. Open the MANIFEST.MF tab, and add the following line:

Bundle-Localization: plugin

  1. Using a text editor or another tool, create the plugin.properties file for English labels and text.

  1. Prepare one plugin_XX.properties file for all languages that you support. For XX, substitute the suffix for the applicable language.

  2. Add your labels and text to plugin.properties and plugin_XX.properties. Use the same format for the labels and text that you used for the message properties files.

Content in Sample plugin.properties

view_title=View

Content in Sample plugin_es.properties

view_title=Vista

  1. Put the files in the main folder or top level folder for your project.

  2. Include your plug-in properties files in the build. In Eclipse, open build.properties and select the files.

  3. In order for Sabre Red 360 to read and translate the messages at run-time, replace the label or text in plugin.xml with the key name. Use the following format:

        %key name

        Where key name is the key in the plugin.properties file.

        For every key name in plugin.properties, a key with the same name must be present in plugin.xml.

In the following example of a plugin.xml file, key name is view_title. The developer replaced the text with %view_title. At run-time, Sabre Red 360 substitutes %view_title with the value that is assigned to the view_title key in plugin.properties and plugin_XX.properties.

<view
category="com.sabre.edge.app.ui.category"
class="com.sabre.redapp.example.i18n.view.I18nView"
icon="images/example.png"
id="com.sabre.redapp.example.i18n.view"
name="%view_title"
restorable="false">
</view>

Modifying the Language in Your Run Configuration to Test Your Plug-in

Before you can test your results, change the language setting in your run configuration.

  1. From the workbench main menu, choose Run > Run Configurations.

  2. On the Arguments tab, in Program Arguments, set the value of the 2-letter abbreviation of the language that you want to test. Examples of program arguments that display the text in both Spanish and English are shown below.

Arguments to Run a Plug-in Using English

-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl en –consoleLog

Arguments to Run a Plug-in Using Spanish

-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl es –consoleLog

When you view the plug-in in Sabre Red 360, verify that the text is displayed in the language that you selected.