From e70ab80b9054b79a713b7f639584db6f66a47b50 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 4 Mar 2023 01:16:30 +0100 Subject: [PATCH] Ignore duplicated preferred l10n locales --- apps/openmw_test_suite/lua/test_l10n.cpp | 1 - components/l10n/manager.cpp | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/openmw_test_suite/lua/test_l10n.cpp b/apps/openmw_test_suite/lua/test_l10n.cpp index e5558e5010..79f126df86 100644 --- a/apps/openmw_test_suite/lua/test_l10n.cpp +++ b/apps/openmw_test_suite/lua/test_l10n.cpp @@ -94,7 +94,6 @@ you_have_arrows: "Arrows count: {count}" internal::CaptureStdout(); l.safe_script("t1 = l10n('Test1')"); EXPECT_THAT(internal::GetCapturedStdout(), - "Fallback locale: en\n" "Language file \"l10n/Test1/de.yaml\" is enabled\n" "Language file \"l10n/Test1/en.yaml\" is enabled\n"); diff --git a/components/l10n/manager.cpp b/components/l10n/manager.cpp index 688d3c8a00..3b6db4f774 100644 --- a/components/l10n/manager.cpp +++ b/components/l10n/manager.cpp @@ -1,5 +1,6 @@ #include "manager.hpp" +#include #include #include @@ -11,8 +12,14 @@ namespace l10n void Manager::setPreferredLocales(const std::vector& langs) { mPreferredLocales.clear(); + std::set langSet; for (const auto& lang : langs) + { + if (langSet.contains(lang)) + continue; + langSet.insert(lang); mPreferredLocales.push_back(icu::Locale(lang.c_str())); + } { Log msg(Debug::Info); msg << "Preferred locales:"; @@ -83,10 +90,6 @@ namespace l10n throw std::runtime_error(std::string("Invalid l10n context name: ") + contextName); icu::Locale fallbackLocale(fallbackLocaleName.c_str()); std::shared_ptr ctx = std::make_shared(mPreferredLocales, fallbackLocale); - { - Log msg(Debug::Verbose); - msg << "Fallback locale: " << fallbackLocale.getName(); - } updateContext(contextName, *ctx); mCache.emplace(key, ctx); return ctx;