Default to the language selected in the installer

This commit is contained in:
Thomas Goyne 2014-05-15 10:19:23 -07:00
parent 79c2634f2b
commit 79fd39d6ca
5 changed files with 39 additions and 23 deletions

View file

@ -80,8 +80,10 @@ end;
procedure CurStepChanged(CurStep: TSetupStep); procedure CurStepChanged(CurStep: TSetupStep);
begin begin
CurStepChangedMigration(CurStep); CurStepChangedMigration(CurStep);
if CurStep = ssPostInstall then
begin
SaveStringToFile(ExpandConstant('{app}\installer_config.json'), ExpandConstant('{{"App": {{"Language": "{language}"}}'), False);
end;
end; end;

View file

@ -52,4 +52,3 @@ Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\aegisub
[Run] [Run]
Filename: {app}\aegisub{#ARCH}.exe; Description: {cm:LaunchProgram,Aegisub}; Flags: nowait postinstall skipifsilent Filename: {app}\aegisub{#ARCH}.exe; Description: {cm:LaunchProgram,Aegisub}; Flags: nowait postinstall skipifsilent

View file

@ -34,6 +34,7 @@
#include "aegisublocale.h" #include "aegisublocale.h"
#include "compat.h"
#include "options.h" #include "options.h"
#include "utils.h" #include "utils.h"
@ -58,9 +59,9 @@ wxTranslations *AegisubLocale::GetTranslations() {
return translations; return translations;
} }
void AegisubLocale::Init(wxString const& language) { void AegisubLocale::Init(std::string const& language) {
wxTranslations *translations = GetTranslations(); wxTranslations *translations = GetTranslations();
translations->SetLanguage(language); translations->SetLanguage(to_wx(language));
translations->AddCatalog(AEGISUB_CATALOG); translations->AddCatalog(AEGISUB_CATALOG);
translations->AddStdCatalog(); translations->AddStdCatalog();
@ -69,17 +70,22 @@ void AegisubLocale::Init(wxString const& language) {
active_language = language; active_language = language;
} }
wxString AegisubLocale::PickLanguage() { bool AegisubLocale::HasLanguage(std::string const& language) {
if (!active_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); wxString os_ui_language = GetTranslations()->GetBestTranslation(AEGISUB_CATALOG);
if (!os_ui_language.empty()) if (!os_ui_language.empty())
return os_ui_language; return from_wx(os_ui_language);
} }
wxArrayString langs = GetTranslations()->GetAvailableTranslations(AEGISUB_CATALOG); wxArrayString langs = GetTranslations()->GetAvailableTranslations(AEGISUB_CATALOG);
// No translations available, so don't bother asking the user // No translations available, so don't bother asking the user
if (langs.empty() && !active_language) if (langs.empty() && active_language.empty())
return "en_US"; return "en_US";
langs.insert(langs.begin(), "en_US"); langs.insert(langs.begin(), "en_US");
@ -107,7 +113,7 @@ wxString AegisubLocale::PickLanguage() {
if (dialog.ShowModal() == wxID_OK) { if (dialog.ShowModal() == wxID_OK) {
int picked = dialog.GetSelection(); int picked = dialog.GetSelection();
if (langs[picked] != active_language) if (langs[picked] != active_language)
return langs[picked]; return from_wx(langs[picked]);
} }
return ""; return "";

View file

@ -27,19 +27,16 @@
// //
// Aegisub Project http://www.aegisub.org/ // Aegisub Project http://www.aegisub.org/
/// @file aegisublocale.h #include <string>
/// @see aegisublocale.cpp
/// @ingroup utility
///
#include <wx/string.h>
class wxTranslations; class wxTranslations;
class AegisubLocale { class AegisubLocale {
wxString active_language; std::string active_language;
wxTranslations *GetTranslations(); wxTranslations *GetTranslations();
public: public:
void Init(wxString const& language); void Init(std::string const& language);
wxString PickLanguage(); bool HasLanguage(std::string const& language);
std::string PickLanguage();
}; };

View file

@ -211,6 +211,18 @@ bool AegisubApp::OnInit() {
wxMessageBox("Configuration file is invalid. Error reported:\n" + to_wx(err.GetMessage()), "Error"); 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. // Init commands.
cmd::init_builtin_commands(); cmd::init_builtin_commands();
@ -245,10 +257,10 @@ bool AegisubApp::OnInit() {
StartupLog("Initialize final locale"); StartupLog("Initialize final locale");
// Set locale // Set locale
wxString lang = to_wx(OPT_GET("App/Language")->GetString()); auto lang = OPT_GET("App/Language")->GetString();
if (!lang) { if (lang.empty() || (lang != "en_US" && !locale.HasLanguage(lang))) {
lang = locale.PickLanguage(); lang = locale.PickLanguage();
OPT_SET("App/Language")->SetString(from_wx(lang)); OPT_SET("App/Language")->SetString(lang);
} }
locale.Init(lang); locale.Init(lang);