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 85 of file Translator.h.
|
inlineprivate |
Singleton constructor must be private or protected.
Definition at line 185 of file Translator.h.
|
inlineprivate |
Singleton destructor must be private or protected.
Definition at line 188 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. |
| Exception | If the text domain already exists it raises an exception. If you are not sure about the existence of a text domain, use the exist() method. |
Definition at line 120 of file Translator.cpp.
References exist(), m_textDomainMap, and TE_TR.
| 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). |
Definition at line 131 of file Translator.cpp.
References m_textDomainMap.
Referenced by addTextDomain().
|
static |
Definition at line 38 of file Translator.cpp.
|
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. |
Definition at line 115 of file Translator.cpp.
References m_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. |
Definition at line 45 of file Translator.cpp.
Referenced by translate().
| 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. |
Definition at line 50 of file Translator.cpp.
References m_locale, and m_textDomainMap.
| 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. |
Definition at line 78 of file Translator.cpp.
References translate().
| 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. |
Definition at line 86 of file Translator.cpp.
References m_locale, and m_textDomainMap.
|
private |
If not empty, it is the current locale.
Definition at line 198 of file Translator.h.
Referenced by setLocale(), and translate().
|
private |
A vector from text domains to base directory for the message catalog.
Definition at line 199 of file Translator.h.
Referenced by addTextDomain(), exist(), and translate().