You can use the IBM MobileFirst Platform Foundation framework to enable the translation of 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
The default workspace encoding in Eclipse is
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
Enabling translation of application strings
You can find the
messages.js file, which is intended for application strings, in the
Application messages that are stored in the
messages.js file can be referenced in two ways:
- As an ID of an HTML element with
Enabling translation of system messages
It 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.json file, 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 language
It is possible to detect the locale and the language of the device.
WL.App.getDeviceLanguage() functions to detect the current locale.
Click to download the Studio project.▲