Java contains support for localization through the resource bundles. You might wonder if there is any need for MULTILIZER if the resource bundles can be used to localize applications. In fact MULTILZER does a lot of same job than resource bundles but MULTILIZER does a lot more and much easier.
The following list contains the MULTILIZER advantages over the Resource Bundles:
"ääliö"
vs. "\u00E4\u00E4li\u00E5"
)The following list contains the Resource Bundles advantages of MULTILIZER:
Let's study a very simple application:
import java.awt.*; import java.awt.event.*;
class MainFrame extends Frame implements ActionListener { public MainFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK);
setTitle("Sample Application"); setBackground(SystemColor.control); setSize(300, 200);
GridLayout layout = new GridLayout(3, 1); setLayout(layout);
add(new Label("This is a MULTILIZER sample")); add(new Label("English version"));
Button button = new Button("Close"); button.addActionListener(this); add(button); }
protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); }
public void actionPerformed(ActionEvent e) { System.exit(0); } }
public class Sample { public Sample() { new MainFrame().show(); }
static public void main(String[] args) { new Sample(); } }
If you run the application it looks like this:
The following two sections describe how to localize this application. First using resource bundles and finally using MULTILIZER.
To localize the application usinf the resource bundles you have to do the folliwng changes and additions:
Add the following line
import java.util.*;
Add the following line to the beginning of the contructor
ResourceBundle bundle = ResourceBundle.getBundle("sample");
Change "Sample Application" to "Sample_Application". Wrap "Sample_Application" to bundle.getString()
setTitle(bundle.getString("Sample_Application"));
Change "This is a MULTILIZER sample" to "This_is_a_MULTILIZER_sample". Wrap "This_is_a_MULTILIZER_sample" to bundle.getString()
add(new Label(bundle.getString("This_is_a_MULTILIZER_sample")));
Change "English version" to "English_version". Wrap "English_version" to bundle.getString()
add(new Label(bundle.getString("English_version")));
Wrap "Close" to bundle.getString()
Button button = new Button(bundle.getString("Close"));
You have to change every string to keys and wrap every string inside the getString method.
The next step is the create the properties-files.
Close=Sulje English_version=Englantilainen versio Sample_Application=Esimerkkiohjelma This_is_a_MULTILIZER_sample=T\u00E4m\u00E4 on MULTILIZER-esimerkki
All character having Unicode value geater that 127 must be code using Unicode escapes. This makes the translations hard to read and write. The key names of the above example are rather easy to read. Unfortunately most IDE do not use as clear key names. You might as well get something like this:
s1=Sulje s2=Englantilainen versio s3=Esimerkkiohjelma s4=T\u00E4m\u00E4 on MULTILIZER-esimerkki
This is compact but a real nightmare to the translator because he or she have to continously look at the source code and the original (English) bundle to get the original values of the properties.
When using MULTILIZER you do not have to change the existing code but you add a translator bean to every frame or dialog. In addition you add a dictionary bean to the main frame.
Add the following line
import multilizer.*;
Create a dictionary and translator beans and call the translate method of the translator
TextDictionary dictionary = new TextDictionary(); dictionary.setFileName("sample"); Translator translator = new Translator(); translator.setHost(this); translator.translate();
The next step is to start Language Manager to create the dictionary. It automatically extract all the string from the source code and adds them to the dictionary.
Close Sulje English version Englantilainen versio Sample Application Esimerkkiohjelma This is a MULTILIZER sample Tämä on MULTILIZER-esimerkki
MULTILIZER-dictionaries are real Unicode file. This means that no Unicode escapes (\uXXXX) need to be used. You can either use Language Manager or any Unicode editor to edit dictionary files. No special keys are used but the original strings are alse the keys.
MULTILIZER make is possible to place all the supported languages to the same file:
Close Sulje Stäng English version Englantilainen versio Engelsk version Sample Application Esimerkkiohjelma Exempel applikation This is a MULTILIZER sample Tämä on MULTILIZER-esimerkki Detta är ett MULTILIZER exempel
The following tables summarizes MULTILIZER and Resource bundle comparison.
Property | Resource Bundles | MULTILIZER |
Strings in your source code | The key can not contains any special characters, not ever the space character. This
means that if you had someting like this:str = "This is a string"; you had to change it to: str = bundle.getString("This_is_a_string"); In practive you have to change every string to a special key value. |
You can use whatever characters in your code. You can program using your native language (e.g. English, German, French, etc) |
How to translate strings to the active language? | You have to write code to use bundles. This means that you have wrap everything around
getString method. If you had something like this:setTitle("A sample frame"); Using bundles you change this to: setTitle(bundle.getString("A_sample_frame")); |
Just add the translator component to the frame/dialog. You do not have to add any code to translate individual properties. Translator component does this for you. |
l.setText("This is a sample"); |
l.setText( bundle.getString("This_is_a_sample")); |
l.setText("This is a sample"); |
IDE support | Most Java IDE do not properly support resource bundles. | No IDE support is needed |
Translation data maintenance | In a large project you will have several resource bundles. It is laborous to keep them updated manually. Some IDEs can create resoruce bundles but none is good to keep them syncronized | Use Language Manager to update dictionaries. It automatically picks up all the new strings |
Translation data translation | Property files code characters above standard ASCII using Unicode escapes. This makes them hard to read and write. | Use Language Manager to edit dictionaries. Language Manager shows all characters as they are and with correct font, uses the proper reading order and/or IME. |
This is a sample |
This_is_a_sample=T\u00E4m\u00E4 on esimerkki |
This is a sample Tämä on esimerkki |
Impact to your source code | You have to change your existing code and write some new code. | In most cases you do not have to change your code. Just add MULTILIZER components and write a little bit new code. |
Translation memory and recycling | No support. | Language Manager contains glossaries that can be used to translate your dictionaries. You can easily recycle old dictionaries over and over again. |