Multilingual Support in Custom Panels

JExpress supports the following languages for its installers, uninstallers, and autoupdaters:

English, French, German, Spanish, Japanese, Polish, Portuguese, Dutch, and Italian

You can easily maintain this internationalization with a few simple steps.

  1. Create a text file called english.res that contains key pairs for each phrase you use in your custom panel. For example, if you have the following line in your custom panel:
    JLabel ( "Hi!" );

    But, you want "Hi!" to appear in the native language, then you would create a resource file for each language you want supported and add a key/value pair line for each word or phrase that you want to display as a separate unit.

    For example, if you decide the key will be Hello, then each .res file would contain a line with Hello= followed by the language's word or phrase. Therefore, the english.res file would contain the following line:

    Hello=Hi!

    While, the spanish.res, would include:

    Hello=Hola!

    etc. Whatever is on the right side of the equal sign will appear wherever you reference the label through the LocaleTranslator. getString() method.

  2. You'll want a [language].res file for each language that JExpress supports. The file must contain the same label (e.g., Hello) with the assignment (e.g., Hello=Hola! for the spanish.res file; Hello=Hallo! for the german.res file, etc.).
    • If you don't want to support a particular language, then simply don't create the associated filename.
    • If you don't know how to translate a particular phrase, then you can leave that key pair out of the associated file. Any missing key pairs default to the key pair in english.res.
    • You must use the exact same key in all the .res files. Case and spacing are important.
  3. Add the following line to the constructor for your custom panel
    LocaleTranslator locale = new LocaleTranslator ( ".res" );
  4. Replace the text in your custom panel so it uses the locale. getString() method to display the text for the local language. To continue the example above, your custom panel would now contain the following line:
    JLabel ( locale. getString ( "Hello" ) );

    where "Hello" is replaced with the matching key for the text.

Note: If you're using the JRE or JDK, then you can quickly test your installer with different languages by creating a Pure Java installer and adding the following command line argument before the "-cp" argument:

-Duser.name=[languageCode]

where [languageCode] is the 2 letter code for the language you want to test. For example, if you want to test the French translation and you're using the JRE, then you're command line might look like this:

jre -Duser.language=fr -cp . Test