OverviewYou can use the IBM MobileFirst Platform Foundation framework to add multilingual translation of Hybrid applications into other languages. Items that can be translated are application strings and system messages.
The platform can automatically translate application strings according to a designated file. This tutorial covers the following topics:
- Enabling translation of application strings
- Enabling translation of system messages
- Multilanguage translation
- Detecting the device locale and language
- Sample application
EncodingThe default workspace encoding in Eclipse is
Cp1252. Before you create the MobileFirst project and start the translation work, you must change the default encoding of the Eclipse workspace.
In Eclipse, navigate to Window > Preferences > General > Workspace and change the encoding to
UTF-8. If you have already created a project, you will need to go over each
.jsfile and change its encoding property.
Enabling translation of application stringsYou can find the
messages.jsfile, which is intended for application strings, in the
Application messages that are stored in the
messages.jsfile can be referenced in two ways:
- As an ID of an HTML element with
Enabling translation of system messagesIt is also possible to translate the system messages that the application displays, for example "Internet connection is not available" or "Invalid username or password".
System messages are stored in the
You can find a full list of system messages in the
www\default\worklight\messages\messages.jsonfile, which is inside the generated projects (iOS, Android, Windows Phone 8, and so on,…).
- Set up the default application strings in the
- Override specific strings when required.
- Update the GUI components with the new strings.
You can perform more tasks, such as setting the text direction for right-to-left languages such as Hebrew or Arabic.
Each time that an element is updated, it is updated with different strings according to the active language.
Detecting the device locale and languageIt is possible to detect the locale and the language of the device.
WL.App.getDeviceLanguage()functions to detect the current locale.
Sample applicationClick to download the MobileFirst project. ▲
Last modified on November 09, 2016