|
|
@ -1,5 +1,6 @@
|
|
|
|
#include "manager.hpp"
|
|
|
|
#include "manager.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <unicode/errorcode.h>
|
|
|
|
#include <unicode/errorcode.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
@ -11,8 +12,14 @@ namespace l10n
|
|
|
|
void Manager::setPreferredLocales(const std::vector<std::string>& langs)
|
|
|
|
void Manager::setPreferredLocales(const std::vector<std::string>& langs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mPreferredLocales.clear();
|
|
|
|
mPreferredLocales.clear();
|
|
|
|
|
|
|
|
std::set<std::string> langSet;
|
|
|
|
for (const auto& lang : langs)
|
|
|
|
for (const auto& lang : langs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (langSet.contains(lang))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
langSet.insert(lang);
|
|
|
|
mPreferredLocales.push_back(icu::Locale(lang.c_str()));
|
|
|
|
mPreferredLocales.push_back(icu::Locale(lang.c_str()));
|
|
|
|
|
|
|
|
}
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log msg(Debug::Info);
|
|
|
|
Log msg(Debug::Info);
|
|
|
|
msg << "Preferred locales:";
|
|
|
|
msg << "Preferred locales:";
|
|
|
@ -83,10 +90,6 @@ namespace l10n
|
|
|
|
throw std::runtime_error(std::string("Invalid l10n context name: ") + contextName);
|
|
|
|
throw std::runtime_error(std::string("Invalid l10n context name: ") + contextName);
|
|
|
|
icu::Locale fallbackLocale(fallbackLocaleName.c_str());
|
|
|
|
icu::Locale fallbackLocale(fallbackLocaleName.c_str());
|
|
|
|
std::shared_ptr<MessageBundles> ctx = std::make_shared<MessageBundles>(mPreferredLocales, fallbackLocale);
|
|
|
|
std::shared_ptr<MessageBundles> ctx = std::make_shared<MessageBundles>(mPreferredLocales, fallbackLocale);
|
|
|
|
{
|
|
|
|
|
|
|
|
Log msg(Debug::Verbose);
|
|
|
|
|
|
|
|
msg << "Fallback locale: " << fallbackLocale.getName();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
updateContext(contextName, *ctx);
|
|
|
|
updateContext(contextName, *ctx);
|
|
|
|
mCache.emplace(key, ctx);
|
|
|
|
mCache.emplace(key, ctx);
|
|
|
|
return ctx;
|
|
|
|
return ctx;
|
|
|
|