OBJECTIVE
This document exemplifies the process to support multi-language in a WebClient dynamically via changes at run-time.
This process exemplifies the process to setup and configure an application that will support Multi-language with target languages English, Spanish, and French.
The end-user will be able to change the national language configuration at runtime and the web application will refresh the change to display fields’ labels and a button’s text in the target locale (language).
This document and example was prepared with PLEX 7.1, Java 7, Eclipse Luna Release (4.4.0), WebClient 1.8.2
A Local Model, WebTest, accompanies this document and a test function, impl name: TestGrid, is included to exemplify the development required for the dynamic change of language (locale).
CONFIGURE OBCLIENT.PROPERTIES TO ENABLE MULTI-LANGUAGE SUPPORT
To enable multi-language support add the following properties to the obclient.properties file:
webclient.localization.enabled=Y
webclient.localization.panelproperties=Text,BitmapFile
In addition, there is another setting in obclient.properties that defines the default locale:
locale.language=en
NOTE: In this example the default locale is English (en).
These settings will affect how WebClient generates elements such as labels and buttons’ text in the .wcli files therefore you will have to regenerate all your panel templates as described in the next steps.
SRC/RES FOLDER PER SUPPORTED LOCALE
To provide the resource files for each language (locale) supported by the application it is necessary to manually create a folder for each locale at the lowest level of your package.
For example, if the package name is “WebClientTest”, as in the accompanying Model for these instructions, this would be the location of the folders for each supported locale:
C:\Development\EclipseWorkspace\WebClientTest\PlexModel\Local\Gen\Src\Res\WebClientTest
So the following folders have been created to support ENGLISH (en), SPANISH (es), and FRENC (fr) locales:
To generate the appropriate resource files it is necessary to change the PLEX configuration to the appropriate target language and then generate the source which is then copied to the corresponding src/res folder for each locale supported.
REGENERATE ALL PANEL TEMPLATES IN THE TARGET LOCALES TO SUPPORT
Perform the following process:
LOCALE CHANGES
There are two alternatives for changing the locale:
For a static local change you need to change the following property on the obclient.properties file:
locale.language=XX
Where:
XX = Locale indicator such as EN (English), FR (French), and ES (Spanish)
Example:locale.language=es
Will switch the application’s local to Spanish.
For 2), dynamic changes, the above property can be switched via the use of the Source Code JAVAPI/SetRunOptionValue. The SetRunOptionValue Source Code is shipped with PLEX and allows chaning any runtime option at runtime.
To reflect the changes after a locale switch it is necessary to refresh the application’s page and the following source code can be used:
import com.adcaustin.webclient.*;
((IWebFunction) fnc).getWebPanel().setRefresh();
Example of an implementation with a dynamic locale change/page refresh can be found in the test function TestGrid, in the accompanying Test Model for this document, which includes a language radio-button field that triggers the ChangeLanguage logical event:
In the Action Diagram the functionality retrieves the language value which is assigned to the PropertyValue field.
This PropertyValue field and the PropertyKey = Locale.Language are used to set the WebClient run option value to set the locale, and finally the application’s page is refreshed with the suggested source code:
Another example, not found in the provided Model, can be found in the following image where the code to set the language takes place before the login process of an application. In this additional example, the language is obtained from the request (browser locale) then mapped to the Java Locale, and finally the runtime option (locale) is set.
Once the user has logged in the application knows his preferred language, from a User Database implemented on this system, so that the Locale can be switched to the one in the User Profile table:
DYNAMIC LOCALE CHANGE - RUNTIME TEST
To test the runtime use: http://localhost:8080/TestWeb/wc
Use the language radio control to set and change the locale
SETUP CONSIDERATIONS
Invalid Java version to use with this workspace would display an error with Exit Code = 13 upon launching the workspace:
To specify the Javaw on Eclipse.INI:
Example of an Eclipse.ini modified to specify the Java executable:
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20140603-1326
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
C:\Program Files\Java\jdk1.7.0_71\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx512m
Note that this configuration would only work for the development environment.
Specify the target web server, for example Tomcat, just select export to WAR file on the Web Project and specify such option:
In addition, you can also try the following setting on:
/root/.bashrc
In such file include the following:
export CATALINA_OPTS=-Dfile.encoding=CP1252
To enable UTF-8 although this has not worked consistently therefore an alternative is to convert the entire RES folder where the .panelresource files are located massively to UTF-8 before the Eclipse Build to have the final files in UTF-8 before releasing to Linux. This can be achieved with a utility like TextCrawler (http://www.digitalvolcano.co.uk/tcdownloads.html) or ICONV (http://www.php.net/iconv). The SRC folder includes the RES folder and also the java sources. The reason for converting all is that captions are stored as part of the java code, not the panelresources, so they need to be converted too.
Also, to change the encoding for Tomcat in general, in your production environment, you can do the following: On Windows Edit the file $TOMCAT_HOME\bin\startup.bat and insert or alter the following line, substituting for the desired values: set CATALINA_OPTS=-Dfile.encoding=CP1252. The problem might be that this setting would be global and could affect other applications using Tomcat so use it just if you are certain this global setting is appropriate.