]> git.lyx.org Git - lyx.git/blobdiff - src/support/Messages.cpp
add generic helper class for calling functions in gui thread
[lyx.git] / src / support / Messages.cpp
index 1e49cc62b368d4ed9d5ba9f33c8df7387ad4a1de..d57f5a4fdac18f3922be55b73dbd2d12bb0bbf60 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -72,8 +72,8 @@ namespace lyx {
 
 void Messages::setDefaultLanguage()
 {
-       char * env_lang[5] = {"LANGUAGE", "LC_ALL", "LC_MESSAGES", "LC_MESSAGE",
-               "LANG"};
+       char const * 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())
@@ -105,7 +105,7 @@ void Messages::init()
        int e = errno;
        if (e) {
                LYXERR(Debug::LOCALE, "Error code: " << errno << '\n'
-                       << "Directory : " << package().locale_dir().absFilename() << '\n'
+                       << "Directory : " << package().locale_dir().absFileName() << '\n'
                        << "Rtn value : " << c);
        }
 
@@ -133,11 +133,13 @@ docstring const Messages::get(string const & m) const
 
        // The string was not found, use gettext to generate it
        static string oldLC_ALL;
+       static string oldLANGUAGE;
        if (!lang_.empty()) {
                oldLC_ALL = getEnv("LC_ALL");
                // This GNU extension overrides any language locale
                // wrt gettext.
                LYXERR(Debug::LOCALE, "Setting LANGUAGE to " << lang_);
+               oldLANGUAGE = getEnv("LANGUAGE");
                if (!setEnv("LANGUAGE", lang_))
                        LYXERR(Debug::LOCALE, "\t... failed!");
                // However, setting LANGUAGE does nothing when the
@@ -157,9 +159,10 @@ docstring const Messages::get(string const & m) const
        char const * m_c = m.c_str();
        char const * trans_c = gettext(m_c);
        docstring trans;
-       if (!trans_c)
-               LYXERR(Debug::LOCALE, "Undefined result from gettext");
-       else if (trans_c == m_c) {
+       if (!trans_c) {
+               LYXERR(Debug::LOCALE, "Undefined result from gettext for `" << m << "'.");
+               trans = from_ascii(m);
+       } else if (trans_c == m_c) {
                //LYXERR(Debug::LOCALE, "Same as entered returned");
                trans = from_ascii(m);
        } else {
@@ -173,9 +176,10 @@ docstring const Messages::get(string const & m) const
        // Reset environment variables as they were.
        if (!lang_.empty()) {
                // Reset everything as it was.
-               LYXERR(Debug::LOCALE, "restoring LANGUAGE from " << getEnv("LANGUAGE")
-                       << " to " << main_lang_);
-               if (!setEnv("LANGUAGE", main_lang_))
+               LYXERR(Debug::LOCALE, "restoring LANGUAGE from " 
+                      << getEnv("LANGUAGE")
+                      << " to " << oldLANGUAGE);
+               if (!setEnv("LANGUAGE", oldLANGUAGE))
                        LYXERR(Debug::LOCALE, "\t... failed!");
                LYXERR(Debug::LOCALE, "restoring LC_ALL from " << getEnv("LC_ALL")
                        << " to " << oldLC_ALL);
@@ -201,7 +205,7 @@ docstring const Messages::get(string const & m) const
 
 namespace lyx {
 
-Messages::Messages(string const & l) {}
+Messages::Messages(string const & /* l */) {}
 
 void Messages::init()
 {