Localization QML

A sample project for how to localize your QML application.


Directions to localize an application in QML


  1. Wrap any string you want to translate in the QML with qsTr function

Ex: Button { text: qsTr("Hello") }

  1. 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

  1. 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)

  1. 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.

  1. Open the "translation_ar.ts" file in Qt Linguist (install it using Package Maintenance if it isn't installed)
  1. Translate the strings using Qt Linguist
  1. Release the strings by using File -> Release

You will find a "translation_ar.qm" file created in the "i18n" folder.

  1. Add a Resource file, then add the "translation_ar.qm" under the "/" prefix.
  1. 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.
  1. Check the main.cpp file of the project to see how you should modify your code.
Categories: Localization, Qt, Qt Quick
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
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2011 All rights reserved