This singleton is designed to deal with multi-language text translation in TerraLib. More...
#include <Translator.h>
Public Member Functions | |
void | addTextDomain (const std::string &textDomain, const std::string &dir) |
It adds a new text domain (text catalog). More... | |
bool | exist (const std::string &textDomain) |
It returns true if the text domain (text catalog) exists and false otherwise. More... | |
void | setLocale (const std::string &locale) |
It sets the locale for the Translator. More... | |
std::string | translate (const std::string &message) |
It tries to translate the specified text string. More... | |
std::string | translate (const char *message) |
It tries to translate the specified text string. More... | |
std::string | translate (const std::string &msg1, const std::string &msg2, unsigned int n) |
It tries to translate the specified text string accounting for plural forms. More... | |
std::string | translate (const char *msg1, const char *msg2, unsigned int n) |
It tries to translate the specified text string accounting for plural forms. More... | |
Static Public Member Functions | |
static Translator & | instance () |
Private Member Functions | |
Translator & | operator= (Translator const &) |
Singleton copy assignment operator must be private or protected. More... | |
Translator () | |
Singleton constructor must be private or protected. More... | |
Translator (Translator const &) | |
Singleton copy constructor must be private or protected. More... | |
~Translator () | |
Singleton destructor must be private or protected. More... | |
Private Attributes | |
std::string | m_locale |
If not empty, it is the current locale. More... | |
std::map< std::string, std::vector< std::string > > | m_textDomainMap |
A vector from text domains to base directory for the message catalog. More... | |
This singleton is designed to deal with multi-language text translation in TerraLib.
The Translator job is to manage "Internationalization" of the TerraLib messages. This class is all about Native Language Support. For each string you want to have a translation, you have to use the special macro TR_TR("string") or TE_TR_PLURAL("string1","string2", int). This macro does nothing with your code; its job is just to mark the code fragment that you want to translate and it does all the job of calling the translation for you. The translations are created with the GNU Gettext Utilities.
We provide a cmake module that searchs for all the necessary GNU Gettext tools, and adds a macro that creates the files for your translations. This macro searchs in a given directory for all ".cpp" files and for the given keywords inside the found files, then automatically generates the ".po", ".pot" and ".mo" files when you build your project. The macro implementation can be found in the file build/cmake/modules/FindGettext.cmake.
Note that all marked messages will be part of a .pot file from where you can create several po documents, one for each idiom. These .po files can be used to generate a .mo binary file with the translation.
Definition at line 86 of file Translator.h.
|
inlineprivate |
Singleton constructor must be private or protected.
Definition at line 186 of file Translator.h.
|
inlineprivate |
Singleton destructor must be private or protected.
Definition at line 189 of file Translator.h.
|
private |
Singleton copy constructor must be private or protected.
void te::core::Translator::addTextDomain | ( | const std::string & | textDomain, |
const std::string & | dir | ||
) |
It adds a new text domain (text catalog).
textDomain | A given message domain (just a name). A text domain is the name of the catalog used to translate the message. |
dir | Where the text domain is located. |
bool te::core::Translator::exist | ( | const std::string & | textDomain | ) |
It returns true if the text domain (text catalog) exists and false otherwise.
textDomain | A given message domain (just a name). |
|
static |
|
private |
Singleton copy assignment operator must be private or protected.
void te::core::Translator::setLocale | ( | const std::string & | locale | ) |
It sets the locale for the Translator.
locale | A string of the new locale. |
std::string te::core::Translator::translate | ( | const std::string & | message | ) |
It tries to translate the specified text string.
If no translation is available it will return the original message (always in English).
message | The text to be translated. |
std::string te::core::Translator::translate | ( | const char * | message | ) |
It tries to translate the specified text string.
If no translation is available it will return the original message (always in English).
message | The text to be translated. |
std::string te::core::Translator::translate | ( | const std::string & | msg1, |
const std::string & | msg2, | ||
unsigned int | n | ||
) |
It tries to translate the specified text string accounting for plural forms.
If no translation is available it will return the original message (always in English).
msg1 | The singular form of the text to be translated. |
msg2 | The plural form of the text to be translated. |
n | This parameter is used to determine the plural form. |
std::string te::core::Translator::translate | ( | const char * | msg1, |
const char * | msg2, | ||
unsigned int | n | ||
) |
It tries to translate the specified text string accounting for plural forms.
If no translation is available it will return the original message (always in English).
msg1 | The singular form of the text to be translated. |
msg2 | The plural form of the text to be translated. |
n | This parameter is used to determine the plural form. |
|
private |
If not empty, it is the current locale.
Definition at line 199 of file Translator.h.
|
private |
A vector from text domains to base directory for the message catalog.
Definition at line 200 of file Translator.h.