libqi-api
2.1.4.13
|
This guide will explain how to create internationalization support (ie: dictionaries files) and to use it to translate an application.
This will be done in two steps:
First of all you need to create a po
directory into your root application folder and POTFILES.in in it.
helloapp |_ po |_ POTFILES.in |_ src |_ main.cpp |_ hello.cpp |_ headers |_ hello.h
Into the POTFILES.in you MUST add the relative path of all files you want to translate. For example, if you only have translation in hello.cpp, the POTFILES.in looks like:
$ cat po/POTFILES.in src/hello.cpp
You need to add a translate
node into the qiproject.xml file. This configuration is used by qilinguist
to generate translation files and installation rules.
The qiproject.xml will look like:
<project name="helloApp"> <translate name="helloApp" domain="hello" linguas="fr_FR en_US" tr="gettext" /> /project>
Tag definitions:
name
: The name of the application or library.domain
: The name of the generated dictionary.linguas
: A list of all locales supported formatted as xx_XX (country and language code)tr
: Define if you use gettext or QT internationalization (value can be: "gettext" or "qt").Dictionaries will be install into:
<sdk_path>/share/locale/<name>/<linguas>/LC_MESSAGES/<domain>.mo
Everything is ready to generate and edit dictionaries.
There are two commands to use:
"Content-Type: text/plain; charset=ASCII\n"by
"Content-Type: text/plain; charset=UTF-8\n"
First of all you need to generate or update translatable files by using qilinguist update
. This will create files (into po
folder) you can edit using Linguist from the Qt SDK or poedit for instance.
Once you have translated those files, you need to compile them by using qilinguist release
.
You must add the qi_create_trad(projectname "po") into the CMakeLists.txt root file.
cmake_minimum_required(VERSION 2.8) project(yourProjectName) qi_create_trad(yourProjectName "po")
You need to get a default qi::Translator, then you MUST set the default domain and current locale.
Steps:
name
the name of the application or library.domain
the name of the generated dictionary.locale
the name of the default loacle formatted as xx_XX (country and language code)name
and domain
must be the same as those define into the qiproject.xml locale
must be a locale supported and define into the qiproject.xml, otherwise it will fallback to the default value.You can add some domains by using qi::Translator::addDomain(const std::string &domain). This will allow qi::Translator to look it multiple dictionary.
You can change the locale you want to use by calling qi::Translator::setCurrentLocale(const std::string &locale). This function allows you to set and switch language at runtime.
You have two choices to translate your sentences:
All sentences will be parsed when calling qilinguist update, then generate translation files (ie: po/ts files). Then, at runtime qi::Translator::translate will look for translation regarding initialization done in the last paragraphe.