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 | loadAllTranslations (const std::string &translationsDir) |
It loads all translations on the translation share folder. 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... | |
void | updateTranslationFiles () |
Initializes the translation files, loading it into memory. It will overwrite the pior loaded list. More... | |
~Translator () | |
Singleton destructor must be private or protected. More... | |
Private Attributes | |
bool | m_loadTranslationFiles |
std::string | m_locale |
If not empty, it is the current locale. More... | |
boost::locale::generator * | m_localeGenerator |
std::map< std::string, std::vector< std::string > > | m_textDomainMap |
A vector from text domains to base directory for the message catalog. More... | |
std::locale | m_translationLocale |
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 94 of file Translator.h.
|
private |
Singleton constructor must be private or protected.
|
private |
Singleton destructor must be private or protected.
|
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 |
void te::core::Translator::loadAllTranslations | ( | const std::string & | translationsDir | ) |
It loads all translations on the translation share folder.
|
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 |
Initializes the translation files, loading it into memory. It will overwrite the pior loaded list.
|
private |
Definition at line 219 of file Translator.h.
|
private |
If not empty, it is the current locale.
Definition at line 217 of file Translator.h.
|
private |
Definition at line 220 of file Translator.h.
|
private |
A vector from text domains to base directory for the message catalog.
Definition at line 218 of file Translator.h.
|
private |
Definition at line 221 of file Translator.h.