mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Added detection of OS language on first run
This commit is contained in:
parent
1f525c59c3
commit
fc696fa0b3
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "../lib/CConfigHandler.h"
|
#include "../lib/CConfigHandler.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
|
#include "../lib/Languages.h"
|
||||||
#include "../lib/filesystem/Filesystem.h"
|
#include "../lib/filesystem/Filesystem.h"
|
||||||
#include "../lib/logging/CBasicLogConfigurator.h"
|
#include "../lib/logging/CBasicLogConfigurator.h"
|
||||||
|
|
||||||
@ -74,6 +75,12 @@ MainWindow::MainWindow(QWidget * parent)
|
|||||||
: QMainWindow(parent), ui(new Ui::MainWindow)
|
: QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
load(); // load FS before UI
|
load(); // load FS before UI
|
||||||
|
|
||||||
|
bool setupCompleted = settings["launcher"]["setupCompleted"].Bool();
|
||||||
|
|
||||||
|
if (!setupCompleted)
|
||||||
|
detectPreferredLanguage();
|
||||||
|
|
||||||
updateTranslation(); // load translation
|
updateTranslation(); // load translation
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -103,7 +110,6 @@ MainWindow::MainWindow(QWidget * parent)
|
|||||||
computeSidePanelSizes();
|
computeSidePanelSizes();
|
||||||
|
|
||||||
bool h3DataFound = CResourceHandler::get()->existsResource(ResourceID("DATA/GENRLTXT.TXT"));
|
bool h3DataFound = CResourceHandler::get()->existsResource(ResourceID("DATA/GENRLTXT.TXT"));
|
||||||
bool setupCompleted = settings["launcher"]["setupCompleted"].Bool();
|
|
||||||
|
|
||||||
if (h3DataFound && setupCompleted)
|
if (h3DataFound && setupCompleted)
|
||||||
ui->tabListWidget->setCurrentIndex(TabRows::MODS);
|
ui->tabListWidget->setCurrentIndex(TabRows::MODS);
|
||||||
@ -116,6 +122,30 @@ MainWindow::MainWindow(QWidget * parent)
|
|||||||
UpdateDialog::showUpdateDialog(false);
|
UpdateDialog::showUpdateDialog(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::detectPreferredLanguage()
|
||||||
|
{
|
||||||
|
auto preferredLanguages = QLocale::system().uiLanguages();
|
||||||
|
|
||||||
|
std::string selectedLanguage;
|
||||||
|
|
||||||
|
for (auto const & userLang : preferredLanguages)
|
||||||
|
{
|
||||||
|
logGlobal->info("Preferred language: %s", userLang.toStdString());
|
||||||
|
|
||||||
|
for (auto const & vcmiLang : Languages::getLanguageList())
|
||||||
|
if (vcmiLang.tagIETF == userLang.toStdString())
|
||||||
|
selectedLanguage = vcmiLang.identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
logGlobal->info("Selected language: %s", selectedLanguage);
|
||||||
|
|
||||||
|
if (!selectedLanguage.empty())
|
||||||
|
{
|
||||||
|
Settings node = settings.write["general"]["language"];
|
||||||
|
node->String() = selectedLanguage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::enterSetup()
|
void MainWindow::enterSetup()
|
||||||
{
|
{
|
||||||
ui->startGameButton->setEnabled(false);
|
ui->startGameButton->setEnabled(false);
|
||||||
|
@ -53,6 +53,7 @@ public:
|
|||||||
void updateTranslation();
|
void updateTranslation();
|
||||||
void computeSidePanelSizes();
|
void computeSidePanelSizes();
|
||||||
|
|
||||||
|
void detectPreferredLanguage();
|
||||||
void enterSetup();
|
void enterSetup();
|
||||||
void exitSetup();
|
void exitSetup();
|
||||||
void switchToModsTab();
|
void switchToModsTab();
|
||||||
|
@ -46,6 +46,9 @@ struct Options
|
|||||||
/// encoding that is used by H3 for this language
|
/// encoding that is used by H3 for this language
|
||||||
std::string encoding;
|
std::string encoding;
|
||||||
|
|
||||||
|
/// primary IETF language tag
|
||||||
|
std::string tagIETF;
|
||||||
|
|
||||||
/// VCMI is capable of detecting H3 install in this language
|
/// VCMI is capable of detecting H3 install in this language
|
||||||
bool hasDetection = false;
|
bool hasDetection = false;
|
||||||
|
|
||||||
@ -57,19 +60,19 @@ inline const auto & getLanguageList()
|
|||||||
{
|
{
|
||||||
static const std::array<Options, 12> languages
|
static const std::array<Options, 12> languages
|
||||||
{ {
|
{ {
|
||||||
{ "chinese", "Chinese", "简体中文", "GBK", true, true }, // Note: actually Simplified Chinese
|
{ "chinese", "Chinese", "简体中文", "GBK", "zh", true, true }, // Note: actually Simplified Chinese
|
||||||
{ "english", "English", "English", "CP1252", true, true },
|
{ "english", "English", "English", "CP1252", "en", true, true },
|
||||||
{ "french", "French", "Français", "CP1252", true, true },
|
{ "french", "French", "Français", "CP1252", "fr", true, true },
|
||||||
{ "german", "German", "Deutsch", "CP1252", true, true },
|
{ "german", "German", "Deutsch", "CP1252", "de", true, true },
|
||||||
{ "korean", "Korean", "한국어", "CP949", false, false },
|
{ "korean", "Korean", "한국어", "CP949", "ko", false, false },
|
||||||
{ "polish", "Polish", "Polski", "CP1250", true, true },
|
{ "polish", "Polish", "Polski", "CP1250", "pl", true, true },
|
||||||
{ "russian", "Russian", "Русский", "CP1251", true, true },
|
{ "russian", "Russian", "Русский", "CP1251", "ru", true, true },
|
||||||
{ "spanish", "Spanish", "Español", "CP1252", false, true },
|
{ "spanish", "Spanish", "Español", "CP1252", "es", false, true },
|
||||||
{ "ukrainian", "Ukrainian", "Українська", "CP1251", true, true },
|
{ "ukrainian", "Ukrainian", "Українська", "CP1251", "uk", true, true },
|
||||||
|
|
||||||
{ "other_cp1250", "Other (East European)", "", "CP1251", false, false },
|
{ "other_cp1250", "Other (East European)", "", "CP1251", "", false, false },
|
||||||
{ "other_cp1251", "Other (Cyrillic Script)", "", "CP1250", false, false },
|
{ "other_cp1251", "Other (Cyrillic Script)", "", "CP1250", "", false, false },
|
||||||
{ "other_cp1252", "Other (West European)", "", "CP1252", false, false }
|
{ "other_cp1252", "Other (West European)", "", "CP1252", "", false, false }
|
||||||
} };
|
} };
|
||||||
static_assert(languages.size() == static_cast<size_t>(ELanguages::COUNT), "Languages array is missing a value!");
|
static_assert(languages.size() == static_cast<size_t>(ELanguages::COUNT), "Languages array is missing a value!");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user