+#endif
+ // CTYPE controls what getmessage thinks what encoding the po file uses
+ char const * lc_ctype = setlocale(LC_CTYPE, NULL);
+ string oldCTYPE = lc_ctype ? lc_ctype : "";
+
+ setlocale(LC_CTYPE, lang_.c_str());
+ errno = 0;
+ char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str());
+ int e = errno;
+ if (e) {
+ lyxerr[Debug::DEBUG]
+ << BOOST_CURRENT_FUNCTION << '\n'
+ << "Error code: " << errno << '\n'
+ << "Lang, mess: " << lang_ << " " << m << '\n'
+ << "Directory : " << package().locale_dir() << '\n'
+ << "Rtn value : " << c << endl;
+ }
+
+ if (!bind_textdomain_codeset(PACKAGE, codeset)) {
+ lyxerr[Debug::DEBUG]
+ << BOOST_CURRENT_FUNCTION << '\n'
+ << "Error code: " << errno << '\n'
+ << "Codeset : " << codeset << '\n'
+ << endl;
+ }
+
+ textdomain(PACKAGE);
+ char const * tmp = m.c_str();
+ char const * msg = gettext(tmp);
+ docstring translated;
+ if (!msg || msg == tmp) {
+ if (!msg)
+ lyxerr << "Undefined result from gettext" << endl;
+ //else
+ // lyxerr << "Same as entered returned" << endl;
+ // Some english words have different translations,
+ // depending on context. In these cases the original
+ // string is augmented by context information (e.g.
+ // "To:[[as in 'From page x to page y']]" and
+ // "To:[[as in 'From format x to format y']]".
+ // This means that we need to filter out everything
+ // in double square brackets at the end of the
+ // string, otherwise the user sees bogus messages.
+ // If we are unable to honour the request we just
+ // return what we got in.
+ boost::smatch sub;
+ if (regex_match(m, sub, reg))
+ translated = from_ascii(sub.str(1));
+ else
+ translated = from_ascii(tmp);
+ } else {
+ lyxerr[Debug::DEBUG] << "We got a translation" << endl;
+ char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
+ translated = ucs4;
+ }
+#ifdef HAVE_LC_MESSAGES
+ setlocale(LC_MESSAGES, lang.c_str());
+#endif
+ setlocale(LC_CTYPE, oldCTYPE.c_str());
+
+ std::pair<TranslationCache::iterator, bool> result =
+ cache_.insert(std::make_pair(m, translated));
+
+ BOOST_ASSERT(result.second);
+
+ return result.first->second;
+}
+
+} // namespace lyx
+
+#else // ENABLE_NLS
+// This is the dummy variant.
+
+using std::endl;
+using std::make_pair;
+using std::map;
+using std::string;
+
+namespace lyx {
+
+Messages::Messages(string const & l) {}
+
+
+docstring const Messages::get(string const & m) const
+{
+ // See comment above
+ boost::smatch sub;
+ if (regex_match(m, sub, reg))
+ return from_ascii(sub.str(1));
+ else
+ return from_ascii(m);