diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 02290e83d..1a864917d 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -974,9 +974,36 @@ int GUI_App::extruders_edited_cnt() const preset.config.option("nozzle_diameter")->values.size(); } +wxString GUI_App::current_language_code_safe() const +{ + // Translate the language code to a code, for which Prusa Research maintains translations. + wxString language_code = this->current_language_code(); + size_t idx_underscore = language_code.find(language_code); + if (idx_underscore != wxString::npos) + language_code = language_code.substr(0, idx_underscore); + const std::map mapping { + { "cs", "cs_CZ", }, + { "de", "de_DE", }, + { "es", "es_ES", }, + { "fr", "fr_FR", }, + { "it", "it_IT", }, + { "ja", "ja_JP", }, + { "ko", "ko_KR", }, + { "pl", "pl_PL", }, + { "uk", "uk_UA", }, + { "zh", "zh_CN", }, + }; + auto it = mapping.find(language_code); + if (it != mapping.end()) + language_code = it->second; + else + language_code = "en_US"; + return language_code; +} + void GUI_App::open_web_page_localized(const std::string &http_address) { - wxLaunchDefaultBrowser(http_address + "&lng=" + this->current_language_code()); + wxLaunchDefaultBrowser(http_address + "&lng=" + this->current_language_code_safe()); } void GUI_App::window_pos_save(wxTopLevelWindow* window, const std::string &name) diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 8d0bcfe2f..5c897a701 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -143,7 +143,9 @@ public: bool checked_tab(Tab* tab); void load_current_presets(); - wxString current_language_code() { return m_wxLocale != nullptr ? m_wxLocale->GetCanonicalName() : wxString("en_US"); } + wxString current_language_code() const { return m_wxLocale != nullptr ? m_wxLocale->GetCanonicalName() : wxString("en_US"); } + // Translate the language code to a code, for which Prusa Research maintains translations. Defaults to "en_US". + wxString current_language_code_safe() const; virtual bool OnExceptionInMainLoop(); diff --git a/src/slic3r/GUI/UpdateDialogs.cpp b/src/slic3r/GUI/UpdateDialogs.cpp index 0f72b3b35..2ea904007 100644 --- a/src/slic3r/GUI/UpdateDialogs.cpp +++ b/src/slic3r/GUI/UpdateDialogs.cpp @@ -55,7 +55,7 @@ MsgUpdateSlic3r::MsgUpdateSlic3r(const Semver &ver_current, const Semver &ver_on auto *link = new wxHyperlinkCtrl(this, wxID_ANY, _(L("Changelog && Download")), url_wx); content_sizer->Add(link); } else { - const auto lang_code = wxGetApp().current_language_code().ToStdString(); + const auto lang_code = wxGetApp().current_language_code_safe().ToStdString(); const std::string url_log = (boost::format(URL_CHANGELOG) % lang_code).str(); const wxString url_log_wx = from_u8(url_log); @@ -100,7 +100,7 @@ MsgUpdateConfig::MsgUpdateConfig(const std::vector &updates) : content_sizer->Add(text); content_sizer->AddSpacer(VERT_SPACING); - const auto lang_code = wxGetApp().current_language_code().ToStdString(); + const auto lang_code = wxGetApp().current_language_code_safe().ToStdString(); auto *versions = new wxBoxSizer(wxVERTICAL); for (const auto &update : updates) {