From e9c880deb5b364e969a0bd62063ffd817a2c89a7 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Thu, 21 Aug 2014 14:02:07 +0100 Subject: [PATCH] Set locale earlier during init. May fix #194, if it's the settings file path that's causing the issue. --- src/gui/app.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/gui/app.cpp b/src/gui/app.cpp index 160b4347..2ba1c7b0 100644 --- a/src/gui/app.cpp +++ b/src/gui/app.cpp @@ -119,6 +119,17 @@ namespace loot { LootState::LootState() : _currentGame(0) {} void LootState::Init(const std::string& cmdLineGame) { + // Do some preliminary locale / UTF-8 support setup here, in case the settings file reading requires it. + //Boost.Locale initialisation: Specify location of language dictionaries. + boost::locale::generator gen; + gen.add_messages_path(g_path_l10n.string()); + gen.add_messages_domain("loot"); + + //Boost.Locale initialisation: Generate and imbue locales. + locale::global(gen(Language(Language::english).Locale() + ".UTF-8")); + cout.imbue(locale()); + boost::filesystem::path::imbue(locale()); + // Check if the LOOT local app data folder exists, and create it if not. if (!fs::exists(g_path_local)) { BOOST_LOG_TRIVIAL(info) << "Local app data LOOT folder doesn't exist, creating it."; @@ -178,26 +189,18 @@ namespace loot { // Delete the current CEF debug log. fs::remove(g_path_local / "CEFDebugLog.txt"); - //Set the locale to get encoding and language conversions working correctly. - BOOST_LOG_TRIVIAL(debug) << "Initialising language settings."; - //Defaults in case language string is empty or setting is missing. - string localeId = loot::Language(loot::Language::any).Locale() + ".UTF-8"; - if (_settings["language"]) { + // Now that settings have been loaded, set the locale again to handle translations. + if (_settings["language"] && _settings["language"].as() != Language(Language::english).Locale()) { + BOOST_LOG_TRIVIAL(debug) << "Initialising language settings."; loot::Language lang(_settings["language"].as()); BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lang.Name(); - localeId = lang.Locale() + ".UTF-8"; + + //Boost.Locale initialisation: Generate and imbue locales. + locale::global(gen(lang.Locale() + ".UTF-8")); + cout.imbue(locale()); + boost::filesystem::path::imbue(locale()); } - //Boost.Locale initialisation: Specify location of language dictionaries. - boost::locale::generator gen; - gen.add_messages_path(g_path_l10n.string()); - gen.add_messages_domain("loot"); - - //Boost.Locale initialisation: Generate and imbue locales. - locale::global(gen(localeId)); - cout.imbue(locale()); - boost::filesystem::path::imbue(locale()); - // Detect games & select startup game //-----------------------------------