diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index 04823ca4..53a42a10 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -99,29 +99,7 @@ bool CemuApp::OnInit() wxInitAllImageHandlers(); - - m_languages = GetAvailableLanguages(); - - const sint32 language = GetConfig().language; - const auto it = std::find_if(m_languages.begin(), m_languages.end(), [language](const wxLanguageInfo* info) { return info->Language == language; }); - if (it != m_languages.end() && wxLocale::IsAvailable(language)) - { - if (m_locale.Init(language)) - { - m_locale.AddCatalogLookupPathPrefix(ActiveSettings::GetDataPath("resources").generic_string()); - m_locale.AddCatalog("cemu"); - } - } - - if (!m_locale.IsOk()) - { - if (!wxLocale::IsAvailable(wxLANGUAGE_DEFAULT) || !m_locale.Init(wxLANGUAGE_DEFAULT)) - { - m_locale.Init(wxLANGUAGE_ENGLISH); - m_locale.AddCatalogLookupPathPrefix(ActiveSettings::GetDataPath("resources").generic_string()); - m_locale.AddCatalog("cemu"); - } - } + LocalizeUI(); // fill colour db wxTheColourDatabase->AddColour("ERROR", wxColour(0xCC, 0, 0)); @@ -231,33 +209,44 @@ int CemuApp::FilterEvent(wxEvent& event) return wxApp::FilterEvent(event); } -std::vector CemuApp::GetAvailableLanguages() +std::vector CemuApp::GetLanguages() const { + std::vector availableLanguages(m_availableTranslations); + availableLanguages.insert(availableLanguages.begin(), wxLocale::GetLanguageInfo(wxLANGUAGE_ENGLISH)); + return availableLanguages; +} + +void CemuApp::LocalizeUI() { - const auto path = ActiveSettings::GetDataPath("resources"); - if (!exists(path)) - return {}; - - std::vector result; - for (const auto& p : fs::directory_iterator(path)) + std::unique_ptr translationsMgr(new wxTranslations()); + m_availableTranslations = GetAvailableTranslationLanguages(translationsMgr.get()); + + const sint32 configuredLanguage = GetConfig().language; + bool isTranslationAvailable = std::any_of(m_availableTranslations.begin(), m_availableTranslations.end(), + [configuredLanguage](const wxLanguageInfo* info) { return info->Language == configuredLanguage; }); + if (configuredLanguage == wxLANGUAGE_DEFAULT || isTranslationAvailable) { - if (!fs::is_directory(p)) - continue; + translationsMgr->SetLanguage(static_cast(configuredLanguage)); + translationsMgr->AddCatalog("cemu"); - const auto& path = p.path(); - auto filename = path.filename(); + if (translationsMgr->IsLoaded("cemu") && wxLocale::IsAvailable(configuredLanguage)) + m_locale.Init(configuredLanguage); - const auto* lang_info = wxLocale::FindLanguageInfo(filename.c_str()); - if (!lang_info) - continue; - - const auto language_file = path / "cemu.mo"; - if (!fs::exists(language_file)) - continue; - - result.emplace_back(lang_info); + // This must be run after wxLocale::Init, as the latter sets up its own wxTranslations instance which we want to override + wxTranslations::Set(translationsMgr.release()); } +} - return result; +std::vector CemuApp::GetAvailableTranslationLanguages(wxTranslations* translationsMgr) +{ + wxFileTranslationsLoader::AddCatalogLookupPathPrefix(wxHelper::FromPath(ActiveSettings::GetDataPath("resources"))); + std::vector languages; + for (const auto& langName : translationsMgr->GetAvailableTranslations("cemu")) + { + const auto* langInfo = wxLocale::FindLanguageInfo(langName); + if (langInfo) + languages.emplace_back(langInfo); + } + return languages; } void CemuApp::CreateDefaultFiles(bool first_start) diff --git a/src/gui/CemuApp.h b/src/gui/CemuApp.h index 1dac29f1..cfdab0a2 100644 --- a/src/gui/CemuApp.h +++ b/src/gui/CemuApp.h @@ -13,8 +13,7 @@ public: void OnAssertFailure(const wxChar* file, int line, const wxChar* func, const wxChar* cond, const wxChar* msg) override; int FilterEvent(wxEvent& event) override; - const std::vector& GetLanguages() const { return m_languages; } - static std::vector GetAvailableLanguages(); + std::vector GetLanguages() const; static void CreateDefaultFiles(bool first_start = false); static bool TrySelectMLCPath(fs::path path); @@ -22,11 +21,13 @@ public: private: void ActivateApp(wxActivateEvent& event); + void LocalizeUI(); + static std::vector GetAvailableTranslationLanguages(wxTranslations* translationsMgr); MainWindow* m_mainFrame = nullptr; wxLocale m_locale; - std::vector m_languages; + std::vector m_availableTranslations; }; wxDECLARE_APP(CemuApp); diff --git a/src/gui/GeneralSettings2.cpp b/src/gui/GeneralSettings2.cpp index e406c698..e33cfbf6 100644 --- a/src/gui/GeneralSettings2.cpp +++ b/src/gui/GeneralSettings2.cpp @@ -123,7 +123,7 @@ wxPanel* GeneralSettings2::AddGeneralPage(wxNotebook* notebook) first_row->Add(new wxStaticText(box, wxID_ANY, _("Language"), wxDefaultPosition, wxDefaultSize, 0), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); - wxString language_choices[] = { _("Default"), "English" }; + wxString language_choices[] = { _("Default") }; m_language = new wxChoice(box, wxID_ANY, wxDefaultPosition, wxDefaultSize, std::size(language_choices), language_choices); m_language->SetSelection(0); m_language->SetToolTip(_("Changes the interface language of Cemu\nAvailable languages are stored in the translation directory\nA restart will be required after changing the language")); @@ -928,8 +928,6 @@ void GeneralSettings2::StoreConfig() auto selection = m_language->GetSelection(); if (selection == 0) GetConfig().language = wxLANGUAGE_DEFAULT; - else if (selection == 1) - GetConfig().language = wxLANGUAGE_ENGLISH; else { const auto language = m_language->GetStringSelection(); diff --git a/src/gui/components/wxGameList.cpp b/src/gui/components/wxGameList.cpp index a64b49bf..2c78ea3c 100644 --- a/src/gui/components/wxGameList.cpp +++ b/src/gui/components/wxGameList.cpp @@ -1027,7 +1027,7 @@ void wxGameList::OnGameEntryUpdatedByTitleId(wxTitleIdEvent& event) if (playTimeStat.last_played.year != 0) { const wxDateTime tmp((wxDateTime::wxDateTime_t)playTimeStat.last_played.day, (wxDateTime::Month)playTimeStat.last_played.month, (wxDateTime::wxDateTime_t)playTimeStat.last_played.year, 0, 0, 0, 0); - SetItem(index, ColumnGameStarted, tmp.FormatISODate()); + SetItem(index, ColumnGameStarted, tmp.FormatDate()); } else SetItem(index, ColumnGameStarted, _("never"));