30 #include <boost/locale.hpp> 31 #include <boost/format.hpp> 35 #include "../Exception.h" 36 #include "../utils/Platform.h" 53 #ifdef TERRALIB_TRANSLATOR_ENABLED 56 for(
const auto& domain : dir.second)
59 boost::locale::generator gen;
60 gen.add_messages_domain(domain);
61 gen.add_messages_path(dir.first);
65 std::string translated = boost::locale::translate(message).str(std::locale());
67 if(translated != message)
79 const std::string& msg2,
82 return translate(msg1.c_str(), msg2.c_str(), n);
90 #ifdef TERRALIB_TRANSLATOR_ENABLED 93 for(
const auto& domain : dir.second)
95 boost::locale::generator gen;
96 gen.add_messages_domain(domain);
97 gen.add_messages_path(dir.first);
101 std::string translated = boost::locale::translate(msg1, msg2, n).str(std::locale());
103 if(n == 1 && translated != msg1)
105 else if(n > 1 && translated != msg2)
109 return ((n == 1) ? msg1 : msg2);
111 return ((n == 1) ? msg1 : msg2);
122 if(
exist(textDomain))
124 boost::format err_msg(
TE_TR(
"The text domain %1% already exist."));
135 auto domain = std::find(dir.second.begin(), dir.second.end(), textDomain);
136 if(domain != dir.second.end())
void setLocale(const std::string &locale)
It sets the locale for the Translator.
static Translator & instance()
This singleton is designed to deal with multi-language text translation in TerraLib.
#define TE_TR(message)
It marks a string in order to get translated.
std::string translate(const std::string &message)
It tries to translate the specified text string.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
void addTextDomain(const std::string &textDomain, const std::string &dir)
It adds a new text domain (text catalog).
std::string m_locale
If not empty, it is the current locale.
This class is designed for dealing with multi-language text translation in TerraLib.
Base exception class for TerraLib Core Runtime Library.
bool exist(const std::string &textDomain)
It returns true if the text domain (text catalog) exists and false otherwise.
std::map< std::string, std::vector< std::string > > m_textDomainMap
A vector from text domains to base directory for the message catalog.