]> git.lyx.org Git - lyx.git/blobdiff - src/support/Messages.cpp
Fix layout bug. Pasting text into a cell tried to set Standard layout, because
[lyx.git] / src / support / Messages.cpp
index aec3556d20114df4ef462af4bf6f94053217b283..1e49cc62b368d4ed9d5ba9f33c8df7387ad4a1de 100644 (file)
 
 using namespace std;
 
-namespace {
+namespace lyx {
+
+// Instanciate static member.
+string Messages::main_lang_;
 
-using lyx::docstring;
-using lyx::from_ascii;
+namespace {
 
 void cleanTranslation(docstring & trans) 
 {
@@ -48,7 +50,8 @@ void cleanTranslation(docstring & trans)
        }
 }
 
-}
+} // anonymous
+} // lyx
 
 
 #ifdef ENABLE_NLS
@@ -67,6 +70,22 @@ using namespace lyx::support;
 
 namespace lyx {
 
+void Messages::setDefaultLanguage()
+{
+       char * env_lang[5] = {"LANGUAGE", "LC_ALL", "LC_MESSAGES", "LC_MESSAGE",
+               "LANG"};
+       for (size_t i = 0; i != 5; ++i) {
+               string const lang = getEnv(env_lang[i]);
+               if (lang.empty())
+                       continue;
+               Messages::main_lang_ = lang;
+               return;
+       }
+       // Not found!
+       LYXERR(Debug::LOCALE, "Default language not found!");
+}
+
+
 // This version use the traditional gettext.
 Messages::Messages(string const & l)
        : lang_(l), warned_(false)
@@ -96,6 +115,9 @@ void Messages::init()
        }
 
        textdomain(PACKAGE);
+
+       // Reset default language;
+       setDefaultLanguage();
 }
 
 
@@ -110,10 +132,9 @@ docstring const Messages::get(string const & m) const
                return it->second;
 
        // The string was not found, use gettext to generate it
-
-       string const oldLANGUAGE = getEnv("LANGUAGE");
-       string const oldLC_ALL = getEnv("LC_ALL");
+       static string oldLC_ALL;
        if (!lang_.empty()) {
+               oldLC_ALL = getEnv("LC_ALL");
                // This GNU extension overrides any language locale
                // wrt gettext.
                LYXERR(Debug::LOCALE, "Setting LANGUAGE to " << lang_);
@@ -139,7 +160,7 @@ docstring const Messages::get(string const & m) const
        if (!trans_c)
                LYXERR(Debug::LOCALE, "Undefined result from gettext");
        else if (trans_c == m_c) {
-               LYXERR(Debug::LOCALE, "Same as entered returned");
+               //LYXERR(Debug::LOCALE, "Same as entered returned");
                trans = from_ascii(m);
        } else {
                //LYXERR(Debug::LOCALE, "We got a translation");
@@ -153,8 +174,8 @@ docstring const Messages::get(string const & m) const
        if (!lang_.empty()) {
                // Reset everything as it was.
                LYXERR(Debug::LOCALE, "restoring LANGUAGE from " << getEnv("LANGUAGE")
-                       << " to " << oldLANGUAGE);
-               if (!setEnv("LANGUAGE", oldLANGUAGE))
+                       << " to " << main_lang_);
+               if (!setEnv("LANGUAGE", main_lang_))
                        LYXERR(Debug::LOCALE, "\t... failed!");
                LYXERR(Debug::LOCALE, "restoring LC_ALL from " << getEnv("LC_ALL")
                        << " to " << oldLC_ALL);