Skip to content

Commit

Permalink
fix the language code not correct issue
Browse files Browse the repository at this point in the history
Change-Id: I73092fee16b2e1284ac79e63edbb3165c04d5650
  • Loading branch information
lanewei120 committed Jul 23, 2022
1 parent 0df07fc commit 7a68cc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
28 changes: 25 additions & 3 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,7 @@ void GUI_App::recreate_GUI(const wxString& msg_name)
dlg.Update(80, _L("Loading current presets") + dots);
load_current_presets();
mainframe->Show(true);
mainframe->refresh_plugin_tips();

dlg.Update(90, _L("Loading a mode view") + dots);

Expand Down Expand Up @@ -3601,15 +3602,15 @@ bool GUI_App::load_language(wxString language, bool initial)
// Get the active language from PrusaSlicer.ini, or empty string if the key does not exist.
language = app_config->get("language");
if (! language.empty())
BOOST_LOG_TRIVIAL(trace) << boost::format("language provided by PrusaSlicer.ini: %1%") % language;
BOOST_LOG_TRIVIAL(trace) << boost::format("language provided by PBambuStudio.conf: %1%") % language;
else {
// Get the system language.
const wxLanguage lang_system = wxLanguage(wxLocale::GetSystemLanguage());
if (lang_system != wxLANGUAGE_UNKNOWN) {
m_language_info_system = wxLocale::GetLanguageInfo(lang_system);
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
app_config->set("language", m_language_info_system->CanonicalName.ToUTF8().data());
//app_config->set("language", m_language_info_system->CanonicalName.ToUTF8().data());
} else {
{
std::map<wxString, wxString> language_descptions = {
Expand Down Expand Up @@ -3644,7 +3645,7 @@ bool GUI_App::load_language(wxString language, bool initial)
m_language_info_best = wxLocale::FindLanguageInfo(best_language);
BOOST_LOG_TRIVIAL(trace) << boost::format("Best translation language detected (may be different from user locales): %1%") %
m_language_info_best->CanonicalName.ToUTF8().data();
app_config->set("language", m_language_info_best->CanonicalName.ToUTF8().data());
//app_config->set("language", m_language_info_best->CanonicalName.ToUTF8().data());
}
#ifdef __linux__
wxString lc_all;
Expand Down Expand Up @@ -3716,6 +3717,27 @@ bool GUI_App::load_language(wxString language, bool initial)
language_info = wxLocale::GetLanguageInfo(wxLANGUAGE_ENGLISH_UK);
app_config->set("language", language_info->CanonicalName.ToUTF8().data());
}
else {
// bbs supported languages
//TODO: use a global one with Preference
wxLanguage supported_languages[] {wxLANGUAGE_ENGLISH, wxLANGUAGE_CHINESE_SIMPLIFIED, wxLANGUAGE_GERMAN, wxLANGUAGE_FRENCH, wxLANGUAGE_SPANISH, wxLANGUAGE_SWEDISH, wxLANGUAGE_DUTCH };
std::string cur_language = app_config->get("language");
if (cur_language != "") {
//cleanup the language wrongly set before
const wxLanguageInfo *langinfo = nullptr;
bool embedded_language = false;
for (auto index = 0; index < 7; index++) {
langinfo = wxLocale::GetLanguageInfo(supported_languages[index]);
std::string temp_lan = langinfo->CanonicalName.ToUTF8().data();
if (cur_language == temp_lan) {
embedded_language = true;
break;
}
}
if (!embedded_language)
app_config->erase("app", "language");
}
}

if (! wxLocale::IsAvailable(language_info->Language)) {
// Loading the language dictionary failed.
Expand Down
3 changes: 1 addition & 2 deletions src/slic3r/GUI/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ wxWindow* PreferencesDialog::create_general_page()
// bbs supported languages
wxLanguage supported_languages[]{wxLANGUAGE_ENGLISH, wxLANGUAGE_CHINESE_SIMPLIFIED, wxLANGUAGE_GERMAN, wxLANGUAGE_FRENCH, wxLANGUAGE_SPANISH, wxLANGUAGE_SWEDISH, wxLANGUAGE_DUTCH };


auto translations = wxTranslations::Get()->GetAvailableTranslations(SLIC3R_APP_KEY);
std::vector<const wxLanguageInfo *> language_infos;
language_infos.emplace_back(wxLocale::GetLanguageInfo(wxLANGUAGE_ENGLISH));
Expand All @@ -643,7 +642,7 @@ wxWindow* PreferencesDialog::create_general_page()

if (langinfo == nullptr) continue;

for (auto si = 0; si < sizeof(supported_languages); si++) {
for (auto si = 0; si < 7; si++) {
if (langinfo == wxLocale::GetLanguageInfo(supported_languages[si])) {
language_infos.emplace_back(langinfo);
}
Expand Down

0 comments on commit 7a68cc5

Please sign in to comment.