libqi-api
2.0.6.8
|
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:
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"
"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:
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.
/* * Copyright (c) 2013 Aldebaran Robotics. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the COPYING file. */ #include <iostream> #include <qi/application.hpp> #include <qi/os.hpp> #include <qi/translator.hpp> int main(int argc, char *argv[]) { qi::Application app(argc, argv); app.setName("qitranslate"); qi::Translator &tl = qi::defaultTranslator(app.name()); tl.setCurrentLocale("en_US"); tl.setDefaultDomain("translate"); std::cout << qi::tr("Hi, my name is NAO.") << std::endl; std::cout << qi::tr("Where is Brian?") << std::endl; std::cout << qi::tr("Brian is in the kitchen.") << std::endl; tl.setCurrentLocale("fr_FR"); std::cout << qi::tr("Hi, my name is NAO.") << std::endl; std::cout << qi::tr("Where is Brian?") << std::endl; std::cout << qi::tr("Brian is in the kitchen.") << std::endl; std::cout << qi::tr("Brian is in the kitchen.", "", "en_US") << std::endl; std::cout << qi::tr("Brian is in the kitchen.", "", "fr_FR") << std::endl; }