Set gtk language based on selected language in RT, fixes #4278, kudos to @agriggio

This commit is contained in:
heckflosse 2018-01-06 18:46:20 +01:00
parent 857f39eb88
commit 309eef696b
3 changed files with 29 additions and 3 deletions

View File

@ -94,10 +94,34 @@ struct LocaleToLang : private std::map<std::pair<Glib::ustring, Glib::ustring>,
return "default";
}
std::string getLocale(const Glib::ustring &language) const
{
for (auto &p : *this) {
if (p.second == language) {
std::string ret = p.first.first;
if (!p.first.second.empty()) {
ret += "_" + p.first.second;
}
return ret;
}
}
return "C";
}
};
const LocaleToLang localeToLang;
void setGtkLanguage(const Glib::ustring &language)
{
auto l = localeToLang.getLocale(language);
#ifdef WIN32
putenv(("LANG=" + l).c_str());
#else
setenv("LANG", l.c_str(), true);
#endif
}
}
MultiLangMgr langMgr;
@ -106,8 +130,10 @@ MultiLangMgr::MultiLangMgr ()
{
}
void MultiLangMgr::load (const std::vector<Glib::ustring> &fnames)
void MultiLangMgr::load(const Glib::ustring &language, const std::vector<Glib::ustring> &fnames)
{
setGtkLanguage(language);
translations.clear();
for (const auto& fname : fnames) {

View File

@ -30,7 +30,7 @@ class MultiLangMgr
public:
MultiLangMgr ();
void load(const std::vector<Glib::ustring> &fnames);
void load(const Glib::ustring &language, const std::vector<Glib::ustring> &fnames);
Glib::ustring getStr(const std::string& key) const;
static bool isOSLanguageDetectSupported();
static Glib::ustring getOSUserLanguage();

View File

@ -2323,7 +2323,7 @@ void Options::load (bool lightweight)
}
}
langMgr.load ({localeTranslation, languageTranslation, defaultTranslation});
langMgr.load (options.language, {localeTranslation, languageTranslation, defaultTranslation});
rtengine::init (&options.rtSettings, argv0, rtdir, !lightweight);
}