From 6a12c7014de0d2eb5803f369e9025d43fa71527e Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 Apr 2024 13:23:38 -0300 Subject: [PATCH] Select "English" if the current language is not found in Preferences If the user preferences file (aseprite.ini) contained a non-existent language, the first option of the languages combo box was selected, which might lead to a confusing situation where just opening the preferences dialog will change from English to other language (non-English, the first language in the combobox). --- src/app/commands/cmd_options.cpp | 13 ++++++++++++- src/app/i18n/strings.cpp | 3 ++- src/app/i18n/strings.h | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/app/commands/cmd_options.cpp b/src/app/commands/cmd_options.cpp index 63f9d89fa..c9ad1fcc6 100644 --- a/src/app/commands/cmd_options.cpp +++ b/src/app/commands/cmd_options.cpp @@ -1317,9 +1317,20 @@ private: if (language()->getItemCount() > 0) return; - // Select current language by lang ID + // Check if the current language exists, in other case select English. Strings* strings = Strings::instance(); std::string curLang = strings->currentLanguage(); + bool found = false; + for (const LangInfo& lang : strings->availableLanguages()) { + if (lang.id == curLang) { + found = true; + break; + } + } + if (!found) + curLang = Strings::kDefLanguage; + + // Select current language by lang ID for (const LangInfo& lang : strings->availableLanguages()) { int i = language()->addItem(new LangItem(lang)); if (lang.id == curLang) diff --git a/src/app/i18n/strings.cpp b/src/app/i18n/strings.cpp index 23916637f..1f065c066 100644 --- a/src/app/i18n/strings.cpp +++ b/src/app/i18n/strings.cpp @@ -25,7 +25,8 @@ namespace app { static Strings* singleton = nullptr; -static const char* kDefLanguage = "en"; + +const char* Strings::kDefLanguage = "en"; // static void Strings::createInstance(Preferences& pref, diff --git a/src/app/i18n/strings.h b/src/app/i18n/strings.h index 4ff627192..e115f16d5 100644 --- a/src/app/i18n/strings.h +++ b/src/app/i18n/strings.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2023 Igara Studio S.A. +// Copyright (C) 2023-2024 Igara Studio S.A. // Copyright (C) 2016-2018 David Capello // // This program is distributed under the terms of @@ -25,6 +25,8 @@ namespace app { // Singleton class to load and access "strings/en.ini" file. class Strings : public app::gen::Strings { public: + static const char* kDefLanguage; + static void createInstance(Preferences& pref, Extensions& exts); static Strings* instance();