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:
In addition, there is another setting in obclient.properties that defines the default locale:
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.
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:
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.
Perform the following process:
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:
XX = Locale indicator such as EN (English), FR (French), and ES (Spanish)
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:
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
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:
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:
In such file include the following:
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.