]> git.lyx.org Git - lyx.git/blobdiff - src/messages.C
hopefully fix tex2lyx linking.
[lyx.git] / src / messages.C
index 2b049c705efee0908dbc805f95190f11e96f1f01..90a345470cbaaac57c0cb2aa09bbb14cdfa914c7 100644 (file)
 
 #include <cerrno>
 
-using lyx::support::package;
-using lyx::support::getEnv;
-using lyx::support::setEnv;
 
-using lyx::char_type;
-using lyx::docstring;
-using lyx::from_ascii;
+namespace lyx {
+
+using support::package;
+using support::getEnv;
+using support::setEnv;
 
 using std::string;
 using std::endl;
 
+
+static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
+
+
 #ifdef ENABLE_NLS
 
 
@@ -114,7 +117,7 @@ public:
        docstring const get(string const & m) const
        {
                if (m.empty())
-                       return lyx::from_ascii(m);
+                       return from_ascii(m);
 
                // In this order, see support/filetools.C:
                string lang = getEnv("LC_ALL");
@@ -171,39 +174,34 @@ public:
                }
 
                textdomain(PACKAGE);
-#if 0
-               const char* msg = gettext(m.c_str());
-               string translated(msg ? msg : m);
-               // 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.
-               static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
-               boost::smatch sub;
-               if (regex_match(translated, sub, reg))
-                       translated = sub.str(1);
-#else
                char const * tmp = m.c_str();
                char const * msg = gettext(tmp);
                docstring translated;
-               if (!msg) {
-                       lyxerr << "Undefined result from gettext" << endl;
-                       translated = from_ascii(tmp);
-               } else if (msg == tmp) {
-                       lyxerr << "Same as entered returned" << endl;
-                       translated = from_ascii(tmp);
+               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 << "We got a translation" << endl;
-                       lyx::char_type const * ucs4 = reinterpret_cast<lyx::char_type const *>(msg);
+                       lyxerr[Debug::DEBUG] << "We got a translation" << endl;
+                       char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
                        translated = ucs4;
                }
-#endif
 #ifdef HAVE_LC_MESSAGES
                setlocale(LC_MESSAGES, lang.c_str());
 #endif
@@ -224,9 +222,14 @@ public:
 
        ~Pimpl() {}
 
-       string const get(string const & m) const
+       docstring const get(string const & m) const
        {
-               return m;
+               // See comment above
+               boost::smatch sub;
+               if (regex_match(m, sub, reg))
+                       return from_ascii(sub.str(1));
+               else
+                       return from_ascii(m);
        }
 };
 #endif
@@ -251,3 +254,6 @@ docstring const Messages::get(string const & msg) const
 {
        return pimpl_->get(msg);
 }
+
+
+} // namespace lyx