Java Tutorial

Pseudo-Localization and Testing your Work

In addition to helping you internationalize your code, Globalyzer helps you test your changes by using its Pseudo-Localization tool. Using Pseudo-Localization, you can easily create a copy of your resource files, with each string pseudo-localized. This is a powerful feature to use during your testing, because displaying pseudo-localized strings, rather than just English strings, can help in the following ways:

  • Find strings that were missed during string externalization, or added afterwards.
  • Find encoding issues where a string pseudo-localized with non-English characters does not display properly.
  • Find display layout issues because the longer strings can no longer fit within display constraints.
  • Find concatenated strings - you'll notice these because your displayed string with have some pseudo-characters in the middle, rather than just at the ends.
  • And, most importantly, pseudo-localization testing can be a way to test before strings are translated and without the requirement that you be a native speaker of a target language.
    1. Let's first take a look at the properties file, exampleResources.properties, and which is located under com.lingoport.demo.java.resources in the project explorer.

    2. Open the file using any text editor.

      The file should look approximately like this:

      Note that the name/value pairs consist of the automatically generated keys, such as EXAM_CITY_24, and the display text.

      Now, let's create a pseudo-localized properties file, using Pseudo Localization.

      Note: for this tutorial, we use the %$ ASCII characters as pseudo-characters, so you don't have to run native2ascii on the UTF-8 generated pseudo-localized file. In your i18n work, the UTF-8 pseudo-localized file would have to be run through native2ascii. Lingoport recommends including that native2ascii transformation step as part of the build process for all UTF-8 files in Java.

    3. Select Fix Code=>Resources=>Pseudo Localization....

      By default, it displays the resource filename and type for your current scan.

    4. Fill it in as shown here, using these pseudo-characters: %$ . (Again, you should use non ASCII characters and then run native2ascii in a real world application).

      Use the Locale... button to choose the German (Germany) pseudo-locale.

      Finally, adjust the Percent Length Increase slider to 30%.

      The pseudo-characters will added to both ends of a string, increasing its length by 30%, as has been specified by the slider. The pseudo-localized file will be named exampleResources_de_DE_Pseudo.properties, where "de_DE_Pseudo" is the pseudo-locale.

    5. Click Apply and then Close. Open the pseudo-localized properties file so you can see how Globalyzer has modified each string in the file.

      Note: A backslash within a .properties file indicates to Globalyzer that a space should be added prior to the localized text. As you can see in the text above, the backslashes present in the original properties file have been replaced by spaces.

    6. You're now ready to compile the Java files and run the application. Use the Run Configuration parameters to set the locale and iterate through the en_US, de_DE_Pseudo (pseudo locale), and fr_FR (with actual translated strings). The simplest way to switch configuration is to first ensure that ExampleMain.java is open, then to click on Run=>Run Configurations to open the Arguments tab. At this point you should then add the locale in the Program Argument text entry.

      Hit Apply then Run. Otherwise, to compile a Java file you typically right click on ExampleMain.java and then select Run as/Java Application.

      The Main window should looked like this before externalizing the string, pseudo-localizing them, and correcting the date/time format method calls:

      Here, the pseudo-locale de_DE_Pseudo is retrieved from the I18nUtils.getLocale() method and is used both to format the date/time and to retrieve the pseudo-localized strings. You should hence see an application which looks like this:

      And running with the French locale (with the run configuration parameter set to "fr_FR") will both have a correct string externalization and translation and the proper date and time formatting:


      Note: the locale setting for this tutorial is quite simple. However, in a real application, you would store the locale in the database or some kind of configuration file. It is also common to allow a user to select their locale from a list of supported ones and store it with other user data. Similarly, real world application have to deal with a host of other i18n issues, such as Unicode encoding, database issues, and collation to name a few.


    Some tips with resource files

    1. If you open the ExampleResources.properties with the Resource File Editor, you can click on each key to see the corresponding value in each one of the locales currently supported, including the pseudo-localized file.

    2. In the Resource File Editor, you can double click on a key to see a list of where that key is used in the code and then click on that line to open the actual file at the location of that usage.

    3. Under Fix Code=>Resources, there are some checks in place for unused keys, duplicated keys, and missing keys which may help figure out problems with resource bundles.

    Congratulations! You've completed the tutorial! If you would like more information, check out our other Globalyzer Help or just try Globalyzer on your own source code. If you have questions, be sure to contact us at support@lingoport.com.