Hi everybody! :)
I’m currently trying to replace libintl (from gnu gettext) by
boost::locale lib, in a (mostly) C program (blender, actually).
To do so, I wrote a simplistic wrapper:
#include
#include "boost_locale_wrapper.h"
static boost::locale::generator gen;
/* Called only once */
void boost_locale_init(const char *messages_path, const char
*default_domain)
{
gen.add_messages_path(messages_path);
gen.add_messages_domain(default_domain);
gen.set_default_messages_domain(default_domain);
}
/* Called each time you change locale */
void boost_locale_set(const char *locale)
{
if (locale && locale[0]) {
std::locale::global(gen(locale));
}
else {
std::locale::global(gen(""));
}
}
const char* boost_locale_gettext(const char *msgid)
{
return boost::locale::gettext(msgid).c_str();
}
(this wrapper lib is linked statically with the main app)
But I'm facing a big problem: I would expect strings returned by
boost::locale::gettext & co to be "const", i.e. that the char pointer
gotten by boost::locale::gettext(msgid).c_str() would be const (and
unique to a given locale/msgid/context/etc.), as it is with gnu gettext.
But this is obviously not the case, as demonstrated by those prints
(translated_msgid (address)):
Serbe latin (Srpski latinica) (0x7fcaed0dac58)
sr_RS@latin (0x7fcaee1e5628)
Suédois (Svenska) (0x7fcaed0dac58)
sv_SE (0x7fcaee1e5628)
Am I missing something obvious here, or are returned string just not
"const"? If so, how can a code like:
MessageBoxW(0,pgettext
http://www.boost.org/doc/libs/1_49_0/libs/locale/doc/html/group__message.htm...(L"File
Dialog",L"Open?").c_str(),gettext
http://www.boost.org/doc/libs/1_49_0/libs/locale/doc/html/group__message.htm...(L"Question").c_str(),MB_YESNO);
(taken from boost doc) could work?
I'm quite new to all this C++2C stuff (and to boost too), so please
forgive me if this is a noob question...
Best regards,
Bastien