A sample project for how to localize your QML application.
Directions to localize an application in QML
- Wrap any string you want to translate in the QML with qsTr function
Ex: Button { text: qsTr("Hello") }
- If your project path is:
C:\Users\sabbour\Work\Code\QtProjects?\LocalizationDemo?
And contains the following directories: C:\Users\sabbour\Work\Code\QtProjects?\LocalizationDemo?\qml C:\Users\sabbour\Work\Code\QtProjects?\LocalizationDemo?\qmlapplicationviewer C:\Users\sabbour\Work\Code\QtProjects?\LocalizationDemo?\...
Create a subfolder in your project path called "i18n" C:\Users\sabbour\Work\Code\QtProjects?\LocalizationDemo?\i18n
- Open a Qt Command Prompt (You have to have the Qt Desktop target installed)
Start -> All Programs -> Qt SDK -> Desktop -> Qt 4.7.4 for Desktop (MinGW)
- Type the following command
lupdate qml\ -ts i18n\translation_ar.ts
This parses your "qml" subfolder recursively and generates a translation file called "translation_ar.ts" in your i18n subdirectory. The "_ar" suffix indicates it is an Arabic translation.
- Open the "translation_ar.ts" file in Qt Linguist (install it using Package Maintenance if it isn't installed)
- Translate the strings using Qt Linguist
- Release the strings by using File -> Release
You will find a "translation_ar.qm" file created in the "i18n" folder.
- Add a Resource file, then add the "translation_ar.qm" under the "/" prefix.
- Modify your main.cpp to include <QTranslator> and <QLocale> and "install" the translation file applicable to your desired locale, whether it comes from your application settings or it is dependant on the device locale.
- Check the main.cpp file of the project to see how you should modify your code.
License:
Development status: Beta
Created: January 23rd, 2012
Visibility: Public
Be the first to follow
Project team
-
Project owners:
-
Public contributors:authenticated
-
Public viewers:anonymous

