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