#include <config.h>
+#include "debug.h"
#include "messages.h"
#include "support/filetools.h"
-#include "support/path_defines.h"
+#include "support/package.h"
#include <boost/regex.hpp>
-using lyx::support::GetEnvPath;
-using lyx::support::lyx_localedir;
+using lyx::support::package;
using std::string;
//lyxerr << "Messages: language(" << l
// << ") in dir(" << dir << ")" << std::endl;
- cat_gl = mssg_gl.open(PACKAGE, loc_gl, lyx_localedir().c_str());
+ cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().c_str());
}
Pimpl(string const & l)
: lang_(l)
{
- //lyxerr << "Messages: language(" << l
- // << ") in dir(" << dir << ")" << std::endl;
-
+ if ( lang_.empty() )
+ lang_ = setlocale(LC_MESSAGES, NULL);
+ lyxerr << "Messages: language(" << lang_
+ // << ") in dir(" << dir
+ << ")" << std::endl;
+
}
~Pimpl() {}
if (m.empty())
return m;
- char * old = strdup(setlocale(LC_ALL, 0));
- char * n = setlocale(LC_ALL, lang_.c_str());
- bindtextdomain(PACKAGE, lyx_localedir().c_str());
+ string oldMSG = setlocale(LC_MESSAGES, NULL);
+ bool works = setlocale(LC_MESSAGES, lang_.c_str());
+ // CTYPE controls what getmessage thinks what encoding the po file uses
+ string oldCTYPE = setlocale(LC_CTYPE, NULL);
+ setlocale(LC_CTYPE, lang_.c_str());
+ bindtextdomain(PACKAGE, package().locale_dir().c_str());
textdomain(PACKAGE);
const char* msg = gettext(m.c_str());
+ string translated(works ? msg : m);
// Some english words have different translations, depending
// on context. In these cases the original string is
// augmented by context information (e.g.
// otherwise the user sees bogus messages.
// If we are unable to honour the request we just
// return what we got in.
- string translated(n ? msg : m);
static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
boost::smatch sub;
if (regex_match(translated, sub, reg))
translated = sub.str(1);
- setlocale(LC_ALL, old);
- free(old);
+ setlocale(LC_MESSAGES, oldMSG.c_str());
+ setlocale(LC_CTYPE, oldCTYPE.c_str());
return translated;
}
private: