This document explains routine changes you must make to support localized pages for the portal.
To avoid the editing of TMX files directly there is the TMX Localization Editor . This project was developed to aid in the manipulation of localization files by providing a graphical interface and some useful features.
The following describes the file that must be modified to properly add localized text to the portal. This file contains all of the translations for each language used in the portal. If a standard feature is added, chances are you will have to add any static text the user sees to this file complete with translations for each locale. The configuration file is available in our repository as Localization.tmx20.xml
To properly add a string to the localization file, you must create a "translation unit" within the "<tmx:body>" open/close tags. Follow the example below and substitute the example values with your own. As the number of locales increase, a translation will have to be added for each unit.
<tmx:tu tuid="theKeyForYourLabel">
<tmx:tuv xml:lang="fr">
<tmx:seg>(French translation for this label)</tmx:seg>
</tmx:tuv>
<tmx:tuv xml:lang="es">
<tmx:seg>(Spanish translation for this label)</tmx:seg>
</tmx:tuv>
<tmx:tuv xml:lang="ru">
<tmx:seg>(Russian translation for this label)</tmx:seg>
</tmx:tuv>
<tmx:tuv xml:lang="en">
<tmx:seg>(English translation for this label)</tmx:seg>
</tmx:tuv>
</tmx:tu>
To refer to this translation unit as a variable in the portal, follow the example below for a .jsp file.
<h:outputText value="#{txt.theKeyForYourLabel}"/>
The localization resources are loaded into a bean that is accessible from the portal .jsp's. This enables the entire portal to be converted into the supported languages on the fly as the user selects from supported locales.
It may be a requirement to remove or add a new language to the ones the portal supports. If this is the case, there are a few more steps that must be taken involving a few configuration files and some Java classes.
The base-utils module directory base-utils\src\main\java\net\sf\gateway\portal\locales contains Java classes that extend ResourceBundle.java such as ResourceBundle_fr.java . By looking at these classes you can tell they simply represent the 2-letter language codes we used in the localization files such as "en", "fr" etc.
package net.sf.gateway.portal.locales;
import java.util.Locale;
/**
* Facade for French localization resource bundle.
*/
public class ResourceBundle_fr extends ResourceBundle {
/**
* Gets the language table for the French language.
*
* @return an object array of key-value pairs.
*/
protected Object[][] getContents() {
return getContents(new Locale("fr"));
}
}
All that is needed for this step is to create a new class, identical to the one displayed above, with it's name and return value for the getContents function redefined. This is as simple as replacing the "fr" in the example above at the following lines with a language code such as "cs":
...
public class ResourceBundle_cs extends ResourceBundle {
...
return getContents(new Locale("cs"));
...
Save the new class as ResourceBundle_cs.java.
Removal: If you are removing a language, you would delete the desired file of a similar name.
Next we need to edit the faces-config.xml in sstp-server-portal\src\main\webapp\WEB-INF .
<application>
<message-bundle>LocalizationResources</message-bundle>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>ru</supported-locale>
<supported-locale>cs</supported-locale>
</locale-config>
</application>
Notice that our new language "cs" is added to the list at the bottom.
Removal: If you are removing a language, you would remove the supported-locale tags and value corresponding to that language.
To use the new language you will have to add values for it to every key used in the portal. Otherwise no text will be displayed on the portal pages. The following is an example of adding a new value to a key:
<tmx:tu tuid="theKeyForYourLabel">
<tmx:tuv xml:lang="cs">
<tmx:seg>(Tanslation for your new language for this label!)</tmx:seg>
</tmx:tuv>
<tmx:tuv xml:lang="fr">
<tmx:seg>(French translation for this label)</tmx:seg>
</tmx:tuv>
<tmx:tuv xml:lang="es">
<tmx:seg>(Spanish translation for this label)</tmx:seg>
</tmx:tuv>
<tmx:tuv xml:lang="ru">
<tmx:seg>(Russian translation for this label)</tmx:seg>
</tmx:tuv>
<tmx:tuv xml:lang="en">
<tmx:seg>(English translation for this label)</tmx:seg>
</tmx:tuv>
</tmx:tu>