FIX: [STUDIO-3005] support sub language (region) in locale
Change-Id: If7af7fc79d84f68dcc495f8f8eefa928e93994a1
This commit is contained in:
parent
767edb03e0
commit
7cba0882b8
|
@ -4830,30 +4830,18 @@ bool GUI_App::load_language(wxString language, bool initial)
|
||||||
const wxLanguage lang_system = wxLanguage(wxLocale::GetSystemLanguage());
|
const wxLanguage lang_system = wxLanguage(wxLocale::GetSystemLanguage());
|
||||||
if (lang_system != wxLANGUAGE_UNKNOWN) {
|
if (lang_system != wxLANGUAGE_UNKNOWN) {
|
||||||
m_language_info_system = wxLocale::GetLanguageInfo(lang_system);
|
m_language_info_system = wxLocale::GetLanguageInfo(lang_system);
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
WCHAR wszLanguagesBuffer[LOCALE_NAME_MAX_LENGTH];
|
||||||
|
::LCIDToLocaleName(LOCALE_USER_DEFAULT, wszLanguagesBuffer, LOCALE_NAME_MAX_LENGTH, 0);
|
||||||
|
wxString lang(wszLanguagesBuffer);
|
||||||
|
lang.Replace('-', '_');
|
||||||
|
if (auto info = wxLocale::FindLanguageInfo(lang))
|
||||||
|
m_language_info_system = info;
|
||||||
|
#endif
|
||||||
BOOST_LOG_TRIVIAL(trace) << boost::format("System language detected (user locales and such): %1%") % m_language_info_system->CanonicalName.ToUTF8().data();
|
BOOST_LOG_TRIVIAL(trace) << boost::format("System language detected (user locales and such): %1%") % m_language_info_system->CanonicalName.ToUTF8().data();
|
||||||
// BBS set language to app config
|
// BBS set language to app config
|
||||||
app_config->set("language", m_language_info_system->CanonicalName.ToUTF8().data());
|
app_config->set("language", m_language_info_system->CanonicalName.ToUTF8().data());
|
||||||
} else {
|
} else {
|
||||||
{
|
|
||||||
std::map<wxString, wxString> language_descptions = {
|
|
||||||
{"zh_CN", wxString::FromUTF8("\xE4\xB8\xAD\xE6\x96\x87\x28\xE7\xAE\x80\xE4\xBD\x93\x29")},
|
|
||||||
{"zh_TW", wxString::FromUTF8("\xE4\xB8\xAD\xE6\x96\x87\x28\xE7\xB9\x81\xE9\xAB\x94\x29")},
|
|
||||||
{"de", wxString::FromUTF8("Deutsch")},
|
|
||||||
{"nl", wxString::FromUTF8("Nederlands")},
|
|
||||||
{"sv", wxString::FromUTF8("\x53\x76\x65\x6e\x73\x6b\x61")}, //Svenska
|
|
||||||
{"en", wxString::FromUTF8("English")},
|
|
||||||
{"es", wxString::FromUTF8("\x45\x73\x70\x61\xC3\xB1\x6F\x6C")},
|
|
||||||
{"fr", wxString::FromUTF8("\x46\x72\x61\x6E\xC3\xA7\x61\x69\x73")},
|
|
||||||
{"it", wxString::FromUTF8("\x49\x74\x61\x6C\x69\x61\x6E\x6F")},
|
|
||||||
{"ru", wxString::FromUTF8("\xD1\x80\xD1\x83\xD1\x81\xD1\x81\xD0\xBA\xD0\xB8\xD0\xB9")},
|
|
||||||
{"hu", wxString::FromUTF8("Magyar")},
|
|
||||||
{"ja", wxString::FromUTF8("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E")}
|
|
||||||
};
|
|
||||||
for (auto l : language_descptions) {
|
|
||||||
const wxLanguageInfo *langinfo = wxLocale::FindLanguageInfo(l.first);
|
|
||||||
if (langinfo) const_cast<wxLanguageInfo *>(langinfo)->Description = l.second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
// Allocating a temporary locale will switch the default wxTranslations to its internal wxTranslations instance.
|
// Allocating a temporary locale will switch the default wxTranslations to its internal wxTranslations instance.
|
||||||
wxLocale temp_locale;
|
wxLocale temp_locale;
|
||||||
|
@ -4945,35 +4933,35 @@ bool GUI_App::load_language(wxString language, bool initial)
|
||||||
else if (initial) {
|
else if (initial) {
|
||||||
// bbs supported languages
|
// bbs supported languages
|
||||||
//TODO: use a global one with Preference
|
//TODO: use a global one with Preference
|
||||||
wxLanguage supported_languages[]{
|
//wxLanguage supported_languages[]{
|
||||||
wxLANGUAGE_ENGLISH,
|
// wxLANGUAGE_ENGLISH,
|
||||||
wxLANGUAGE_CHINESE_SIMPLIFIED,
|
// wxLANGUAGE_CHINESE_SIMPLIFIED,
|
||||||
wxLANGUAGE_GERMAN,
|
// wxLANGUAGE_GERMAN,
|
||||||
wxLANGUAGE_FRENCH,
|
// wxLANGUAGE_FRENCH,
|
||||||
wxLANGUAGE_SPANISH,
|
// wxLANGUAGE_SPANISH,
|
||||||
wxLANGUAGE_SWEDISH,
|
// wxLANGUAGE_SWEDISH,
|
||||||
wxLANGUAGE_DUTCH,
|
// wxLANGUAGE_DUTCH,
|
||||||
wxLANGUAGE_HUNGARIAN,
|
// wxLANGUAGE_HUNGARIAN,
|
||||||
wxLANGUAGE_JAPANESE,
|
// wxLANGUAGE_JAPANESE,
|
||||||
wxLANGUAGE_ITALIAN
|
// wxLANGUAGE_ITALIAN
|
||||||
};
|
//};
|
||||||
std::string cur_language = app_config->get("language");
|
//std::string cur_language = app_config->get("language");
|
||||||
if (cur_language != "") {
|
//if (cur_language != "") {
|
||||||
//cleanup the language wrongly set before
|
// //cleanup the language wrongly set before
|
||||||
const wxLanguageInfo *langinfo = nullptr;
|
// const wxLanguageInfo *langinfo = nullptr;
|
||||||
bool embedded_language = false;
|
// bool embedded_language = false;
|
||||||
int language_num = sizeof(supported_languages) / sizeof(supported_languages[0]);
|
// int language_num = sizeof(supported_languages) / sizeof(supported_languages[0]);
|
||||||
for (auto index = 0; index < language_num; index++) {
|
// for (auto index = 0; index < language_num; index++) {
|
||||||
langinfo = wxLocale::GetLanguageInfo(supported_languages[index]);
|
// langinfo = wxLocale::GetLanguageInfo(supported_languages[index]);
|
||||||
std::string temp_lan = langinfo->CanonicalName.ToUTF8().data();
|
// std::string temp_lan = langinfo->CanonicalName.ToUTF8().data();
|
||||||
if (cur_language == temp_lan) {
|
// if (cur_language == temp_lan) {
|
||||||
embedded_language = true;
|
// embedded_language = true;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (!embedded_language)
|
// if (!embedded_language)
|
||||||
app_config->erase("app", "language");
|
// app_config->erase("app", "language");
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! wxLocale::IsAvailable(language_info->Language)) {
|
if (! wxLocale::IsAvailable(language_info->Language)) {
|
||||||
|
|
|
@ -104,7 +104,8 @@ wxBoxSizer *PreferencesDialog::create_item_language_combobox(
|
||||||
auto combobox = new ::ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, DESIGN_LARGE_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
|
auto combobox = new ::ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, DESIGN_LARGE_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
|
||||||
combobox->SetFont(::Label::Body_13);
|
combobox->SetFont(::Label::Body_13);
|
||||||
combobox->GetDropDown().SetFont(::Label::Body_13);
|
combobox->GetDropDown().SetFont(::Label::Body_13);
|
||||||
|
auto language = app_config->get(param);
|
||||||
|
m_current_language_selected = -1;
|
||||||
std::vector<wxString>::iterator iter;
|
std::vector<wxString>::iterator iter;
|
||||||
for (size_t i = 0; i < vlist.size(); ++i) {
|
for (size_t i = 0; i < vlist.size(); ++i) {
|
||||||
auto language_name = vlist[i]->Description;
|
auto language_name = vlist[i]->Description;
|
||||||
|
@ -137,11 +138,20 @@ wxBoxSizer *PreferencesDialog::create_item_language_combobox(
|
||||||
language_name = wxString::FromUTF8("\x69\x74\x61\x6c\x69\x61\x6e\x6f");
|
language_name = wxString::FromUTF8("\x69\x74\x61\x6c\x69\x61\x6e\x6f");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_config->get(param) == vlist[i]->CanonicalName) {
|
if (language == vlist[i]->CanonicalName) {
|
||||||
m_current_language_selected = i;
|
m_current_language_selected = i;
|
||||||
}
|
}
|
||||||
combobox->Append(language_name);
|
combobox->Append(language_name);
|
||||||
}
|
}
|
||||||
|
if (m_current_language_selected == -1 && language.size() >= 5) {
|
||||||
|
language = language.substr(0, 2);
|
||||||
|
for (size_t i = 0; i < vlist.size(); ++i) {
|
||||||
|
if (vlist[i]->CanonicalName.StartsWith(language)) {
|
||||||
|
m_current_language_selected = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
combobox->SetSelection(m_current_language_selected);
|
combobox->SetSelection(m_current_language_selected);
|
||||||
|
|
||||||
m_sizer_combox->Add(combobox, 0, wxALIGN_CENTER, 0);
|
m_sizer_combox->Add(combobox, 0, wxALIGN_CENTER, 0);
|
||||||
|
|
Loading…
Reference in New Issue