From 79fd39d6ca230f66750f16461c24aacb2d63feda Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 15 May 2014 10:19:23 -0700 Subject: [PATCH] Default to the language selected in the installer --- packages/win_installer/aegisub3.iss | 8 +++++--- .../win_installer/fragment_mainprogram.iss | 1 - src/aegisublocale.cpp | 20 ++++++++++++------- src/aegisublocale.h | 15 ++++++-------- src/main.cpp | 18 ++++++++++++++--- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/packages/win_installer/aegisub3.iss b/packages/win_installer/aegisub3.iss index 2888f221b..65e00a2f3 100644 --- a/packages/win_installer/aegisub3.iss +++ b/packages/win_installer/aegisub3.iss @@ -80,8 +80,10 @@ end; procedure CurStepChanged(CurStep: TSetupStep); begin CurStepChangedMigration(CurStep); + + if CurStep = ssPostInstall then + begin + SaveStringToFile(ExpandConstant('{app}\installer_config.json'), ExpandConstant('{{"App": {{"Language": "{language}"}}'), False); + end; end; - - - diff --git a/packages/win_installer/fragment_mainprogram.iss b/packages/win_installer/fragment_mainprogram.iss index 8d2379ba3..a725bf15c 100644 --- a/packages/win_installer/fragment_mainprogram.iss +++ b/packages/win_installer/fragment_mainprogram.iss @@ -52,4 +52,3 @@ Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\aegisub [Run] Filename: {app}\aegisub{#ARCH}.exe; Description: {cm:LaunchProgram,Aegisub}; Flags: nowait postinstall skipifsilent - diff --git a/src/aegisublocale.cpp b/src/aegisublocale.cpp index 9a1258cd0..bf1879c50 100644 --- a/src/aegisublocale.cpp +++ b/src/aegisublocale.cpp @@ -34,6 +34,7 @@ #include "aegisublocale.h" +#include "compat.h" #include "options.h" #include "utils.h" @@ -58,9 +59,9 @@ wxTranslations *AegisubLocale::GetTranslations() { return translations; } -void AegisubLocale::Init(wxString const& language) { +void AegisubLocale::Init(std::string const& language) { wxTranslations *translations = GetTranslations(); - translations->SetLanguage(language); + translations->SetLanguage(to_wx(language)); translations->AddCatalog(AEGISUB_CATALOG); translations->AddStdCatalog(); @@ -69,17 +70,22 @@ void AegisubLocale::Init(wxString const& language) { active_language = language; } -wxString AegisubLocale::PickLanguage() { - if (!active_language) { +bool AegisubLocale::HasLanguage(std::string const& language) { + auto langs = GetTranslations()->GetAvailableTranslations(AEGISUB_CATALOG); + return find(langs.begin(), langs.end(), to_wx(language)) != end(langs); +} + +std::string AegisubLocale::PickLanguage() { + if (active_language.empty()) { wxString os_ui_language = GetTranslations()->GetBestTranslation(AEGISUB_CATALOG); if (!os_ui_language.empty()) - return os_ui_language; + return from_wx(os_ui_language); } wxArrayString langs = GetTranslations()->GetAvailableTranslations(AEGISUB_CATALOG); // No translations available, so don't bother asking the user - if (langs.empty() && !active_language) + if (langs.empty() && active_language.empty()) return "en_US"; langs.insert(langs.begin(), "en_US"); @@ -107,7 +113,7 @@ wxString AegisubLocale::PickLanguage() { if (dialog.ShowModal() == wxID_OK) { int picked = dialog.GetSelection(); if (langs[picked] != active_language) - return langs[picked]; + return from_wx(langs[picked]); } return ""; diff --git a/src/aegisublocale.h b/src/aegisublocale.h index 5ea878f61..bb95d60ed 100644 --- a/src/aegisublocale.h +++ b/src/aegisublocale.h @@ -27,19 +27,16 @@ // // Aegisub Project http://www.aegisub.org/ -/// @file aegisublocale.h -/// @see aegisublocale.cpp -/// @ingroup utility -/// - -#include +#include class wxTranslations; class AegisubLocale { - wxString active_language; + std::string active_language; wxTranslations *GetTranslations(); + public: - void Init(wxString const& language); - wxString PickLanguage(); + void Init(std::string const& language); + bool HasLanguage(std::string const& language); + std::string PickLanguage(); }; diff --git a/src/main.cpp b/src/main.cpp index 9bc305bb2..0696d1576 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -211,6 +211,18 @@ bool AegisubApp::OnInit() { wxMessageBox("Configuration file is invalid. Error reported:\n" + to_wx(err.GetMessage()), "Error"); } +#ifdef _WIN32 + StartupLog("Load installer configuration"); + if (OPT_GET("App/First Start")->GetBool()) { + try { + auto installer_config = agi::io::Open(config::path->Decode("?data/installer_config.json")); + config::opt->ConfigNext(*installer_config.get()); + } catch (agi::fs::FileSystemError const&) { + // Not an error obviously as the user may not have used the installer + } + } +#endif + // Init commands. cmd::init_builtin_commands(); @@ -245,10 +257,10 @@ bool AegisubApp::OnInit() { StartupLog("Initialize final locale"); // Set locale - wxString lang = to_wx(OPT_GET("App/Language")->GetString()); - if (!lang) { + auto lang = OPT_GET("App/Language")->GetString(); + if (lang.empty() || (lang != "en_US" && !locale.HasLanguage(lang))) { lang = locale.PickLanguage(); - OPT_SET("App/Language")->SetString(from_wx(lang)); + OPT_SET("App/Language")->SetString(lang); } locale.Init(lang);