Ignore duplicated preferred l10n locales

depth-refraction
Petr Mikheev 2 years ago
parent 88567cd363
commit e70ab80b90

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

@ -1,5 +1,6 @@
#include "manager.hpp"
#include <set>
#include <unicode/errorcode.h>
#include <components/debug/debuglog.hpp>
@ -11,8 +12,14 @@ namespace l10n
void Manager::setPreferredLocales(const std::vector<std::string>& langs)
{
mPreferredLocales.clear();
std::set<std::string> 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<MessageBundles> ctx = std::make_shared<MessageBundles>(mPreferredLocales, fallbackLocale);
{
Log msg(Debug::Verbose);
msg << "Fallback locale: " << fallbackLocale.getName();
}
updateContext(contextName, *ctx);
mCache.emplace(key, ctx);
return ctx;

Loading…
Cancel
Save