How to use

This chapter describes how to use MULTILIZER. To make your application multilingual complete the following steps:

  1. Create the dictionary
  2. Add a dictionary component to the application
  3. Add a translator component to each frame
  4. Translate the hard coded strings

1. Create the dictionary

Your first job is to create the dictionary. The dictionary contains all the user interface strings of your application. You can create the dictionary manually, but it can be quite laborious. An easier way is to use MULTILIZER Language ManagerTM. It is an application that scans your source codes, extracts all the user interface strings, and let your or your translator easily translate each string. You will need Language Manager only when creating the dictionaries for the application.

2. Add a dictionary component to the application

Each application must have one dictionary. It contains the translation data of the application. The dictionary component must be available all the time. That's why you should place it on the application or on the main frame. The following example contains a main frame that has a binary dictionary.

public class MainFrame extends Frame
{
  BinaryDictionary dictionary = new BinaryDictionary();
    
  public MainForm()
  {
    dictionary.setFileName("sample.mld");
    dictionary.open();
  }
}

Note! Typically you add component and set the properties on the design time using compiler's IDE. Also there is no need to explicitly open the dictionary. The first translator that needs the dictionary opens it.

3. Add a translator component to every frame

The translator component translates the host component from the native language to the active language of the dictionary. Add a translator component to every frame that you want to be multilingual. Set the following properties of the translator:

By default the translator uses the default dictionary (i.e. the first dictionary component created by the application). If you want to use some other dictionary set the dictionaryName property. Finally call the translate or the translate(Container host) method to translate the host component.

This example adds a translator component to the main form.

public class MainFrame extends Frame
{
  BinaryDictionary dictionary = new BinaryDictionary();
  Translator translator = new Translator();
    
  public MainForm()
  {
    dictionary.setFileName("sample.mld");
    translator.translate(this);
  }
}

Note! Typically you add the component and set the properties on the design time using compiler's IDE.  The Targets property contains a property editor that makes is easy to add, remove or edit targets. You only have to call the translate method in the constructor:

public MainForm()
{
  initForm();
  translator.translate();
}

You could use multiple dictionaries, even one dictionary per each form, but this would slow your application and waste memory a lot. A much better approach is to use the dictionary component of the main form for every other forms as well. The following example demonstrates the usage of translator on a secondary form (about box).

public class AboutBox extends Frame
{
  Translator translator = new Translator();
  
  public AboutBox()
  {
    translator.translate(this);
  }
}

4. Translate the hard coded strings

In many times the code contains hard coded string. The old way was to isolate these string and put them to the resource. This complicated the programming and made those code harder to read and maintain. MULTILIZER lets you use the hard code string. You just have to wrap them with the translate method. This method translates the string to the active language.

For example if you had the following line

str = "This is a sample string";

Change it to

str = translator.translate("This is a sample string");

 

More information about internationalization can be found from MULTILIZER web pages: http://www.multilizer.com/documents/j3intl/index.htm