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);
begin
CurStepChangedMigration(CurStep);
if CurStep = ssPostInstall then
begin
SaveStringToFile(ExpandConstant('{app}\installer_config.json'), ExpandConstant('{{"App": {{"Language": "{language}"}}'), False);
end;
end;

View file

@ -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

View file

@ -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 "";

View file

@ -27,19 +27,16 @@
//
// Aegisub Project http://www.aegisub.org/
/// @file aegisublocale.h
/// @see aegisublocale.cpp
/// @ingroup utility
///
#include <wx/string.h>
#include <string>
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();
};

View file

@ -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);