Jürgen Spitzmüller <juer...@spitzmueller.org> writes: > Jean-Marc, is this OK, or should we rather try to make the backend aware of > LC_NUMERIC? If so, I need your help.
While I am not sure about whre you are headed, here is a patch that might help in the translation dept. It gets rid of the setDefaultLanguage thing, and reuses the trick currently used in i18nLibFileName that lets gettext itself tell us what is the currently loaded mo file. This is something I have been wanting to do for a long time. Only problem is that it breaks compilation in client/ and tex2lyx/. And maybe also that I have no tim e to test it right now :) JMarc
svndiff support/ frontends/ Index: support/filetools.cpp =================================================================== --- support/filetools.cpp (revision 28180) +++ support/filetools.cpp (working copy) @@ -28,6 +28,7 @@ #include "support/environment.h" #include "support/gettext.h" #include "support/lstrings.h" +#include "support/Messages.h" #include "support/os.h" #include "support/Package.h" #include "support/Path.h" @@ -236,18 +237,7 @@ FileName const libFileSearch(string cons FileName const i18nLibFileSearch(string const & dir, string const & name, string const & ext) { - /* The highest priority value is the `LANGUAGE' environment - variable. But we don't use the value if the currently - selected locale is the C locale. This is a GNU extension. - - Otherwise, w use a trick to guess what support/gettext.has done: - each po file is able to tell us its name. (JMarc) - */ - - string lang = to_ascii(_("[[Replace with the code of your language]]")); - string const language = getEnv("LANGUAGE"); - if (!lang.empty() && !language.empty()) - lang = language; + string lang = getGuiMessages().preferredLanguages(); string l; lang = split(lang, l, ':'); Index: support/Messages.h =================================================================== --- support/Messages.h (revision 28180) +++ support/Messages.h (working copy) @@ -28,15 +28,13 @@ public: docstring const get(std::string const & msg) const; /// static void init(); - /// - static std::string const & defaultLanguage() { return main_lang_; } + /// The language actually loaded by gettext. + std::string language() const; + /// List of languages set by the user (LANGUAGE variable) + std::string preferredLanguages() const; private: /// - static void setDefaultLanguage(); - /// - static std::string main_lang_; - /// std::string lang_; /// Did we warn about unavailable locale already? mutable bool warned_; Index: support/Messages.cpp =================================================================== --- support/Messages.cpp (revision 28180) +++ support/Messages.cpp (working copy) @@ -25,9 +25,6 @@ using namespace std; namespace lyx { -// Instanciate static member. -string Messages::main_lang_; - namespace { void cleanTranslation(docstring & trans) @@ -70,19 +67,27 @@ using namespace lyx::support; namespace lyx { -void Messages::setDefaultLanguage() +string Messages::language() const { - 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()) - continue; - Messages::main_lang_ = lang; - return; - } - // Not found! - LYXERR(Debug::LOCALE, "Default language not found!"); + /* Use a trick to guess what support/gettext.has done: each po + file is able to tell us its name. (JMarc) + */ + return to_ascii(get("[[Replace with the code of your language]]")); +} + + +string Messages::preferredLanguages() const +{ + string const curlang = language(); + + /* The highest priority value is the `LANGUAGE' environment + variable. But we don't use the value if the currently + selected locale is the C locale. This is a GNU extension. + */ + string const langs = getEnv("LANGUAGE"); + if (!curlang.empty() && !langs.empty()) + return langs; + return curlang; } @@ -115,9 +120,6 @@ void Messages::init() } textdomain(PACKAGE); - - // Reset default language; - setDefaultLanguage(); } @@ -133,11 +135,13 @@ docstring const Messages::get(string con // 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 @@ -173,9 +177,10 @@ docstring const Messages::get(string con // 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); Index: frontends/qt4/GuiApplication.cpp =================================================================== --- frontends/qt4/GuiApplication.cpp (revision 28180) +++ frontends/qt4/GuiApplication.cpp (working copy) @@ -1076,7 +1076,7 @@ void GuiApplication::setGuiLanguage() // Set the language defined by the user. setRcGuiLanguage(); - QString const default_language = toqstr(Messages::defaultLanguage()); + QString const default_language = toqstr(getGuiMessages().language()); LYXERR(Debug::LOCALE, "Tring to set default locale to: " << default_language); QLocale const default_locale(default_language); QLocale::setDefault(default_locale);