29 #ifdef TERRALIB_TRANSLATOR_ENABLED
32 #include "Exception.h"
35 #ifdef TERRALIB_GNU_GETTEXT_ENABLED
39 const char* te::common::Translator::translate(
const std::string& message,
const std::string& textDomain)
41 return translate(message.c_str(), textDomain.c_str());
44 const char* te::common::Translator::translate(
const char* message,
const char* textDomain)
46 #ifdef TERRALIB_GNU_GETTEXT_ENABLED
47 return dgettext(textDomain, message);
53 const char* te::common::Translator::translate(
const std::string& textDomain,
54 const std::string& msg1,
55 const std::string& msg2,
58 return translate(textDomain.c_str(), msg1.c_str(), msg2.c_str(), n);
61 const char* te::common::Translator::translate(
const char* textDomain,
66 #ifdef TERRALIB_GNU_GETTEXT_ENABLED
67 return dngettext(textDomain, msg1, msg2, n);
69 return ((n == 1) ? msg1 : msg2);
73 const char* te::common::Translator::addTextDomain(
const std::string& textDomain,
const std::string& textDomainDir)
76 throw Exception(
TE_TR(
"The text domain already exist."));
78 m_textDomainMap[textDomain] = textDomainDir;
80 #ifdef TERRALIB_GNU_GETTEXT_ENABLED
81 return bindtextdomain(textDomain.c_str(), textDomainDir.c_str());
87 const char* te::common::Translator::setTextDomainCodeSet(
const std::string& textDomain,
const std::string& codeset)
89 if(exist(textDomain) ==
false)
90 throw Exception(
TE_TR(
"The text domain doesn't exist."));
92 #ifdef TERRALIB_GNU_GETTEXT_ENABLED
93 return bind_textdomain_codeset(textDomain.c_str(), codeset.c_str());
99 bool te::common::Translator::exist(
const std::string& textDomain)
101 std::map<std::string, std::string>::const_iterator it = m_textDomainMap.find(textDomain);
103 if(it != m_textDomainMap.end())
109 std::string te::common::Translator::getTextDomainDir(
const std::string& textDomain)
111 std::map<std::string, std::string>::const_iterator it = m_textDomainMap.find(textDomain);
113 if(it != m_textDomainMap.end())
116 return std::string(
"");
119 te::common::Translator::Translator()
123 te::common::Translator::~Translator()
127 #endif // TERRALIB_TRANSLATOR_ENABLED
#define TE_TR(message)
It marks a string in order to get translated.
This class is designed for dealing with multi-language text translation in TerraLib.