diff --git a/components/l10n/manager.cpp b/components/l10n/manager.cpp index 77474cd3f5..f6f4bb4f05 100644 --- a/components/l10n/manager.cpp +++ b/components/l10n/manager.cpp @@ -43,10 +43,19 @@ namespace l10n path /= name; path /= langName; - if (!mVFS->exists(path)) + const Files::IStreamPtr stream = mVFS->find(path); + + if (stream == nullptr) return; - ctx.load(*mVFS->get(path), lang, path); + try + { + ctx.load(*stream, lang); + } + catch (const std::exception& e) + { + Log(Debug::Error) << "Cannot load message bundles from " << path << ": " << e.what(); + } } void Manager::updateContext(const std::string& name, MessageBundles& ctx) diff --git a/components/l10n/messagebundles.cpp b/components/l10n/messagebundles.cpp index a46b05c6f4..2948ff155e 100644 --- a/components/l10n/messagebundles.cpp +++ b/components/l10n/messagebundles.cpp @@ -66,33 +66,26 @@ namespace l10n return status.isSuccess(); } - void MessageBundles::load(std::istream& input, const icu::Locale& lang, const std::string& path) + void MessageBundles::load(std::istream& input, const icu::Locale& lang) { - try + YAML::Node data = YAML::Load(input); + std::string localeName = lang.getName(); + const icu::Locale& langOrEn = localeName == "gmst" ? icu::Locale::getEnglish() : lang; + for (const auto& it : data) { - YAML::Node data = YAML::Load(input); - std::string localeName = lang.getName(); - const icu::Locale& langOrEn = localeName == "gmst" ? icu::Locale::getEnglish() : lang; - for (const auto& it : data) + const auto key = it.first.as(); + const auto value = it.second.as(); + icu::UnicodeString pattern + = icu::UnicodeString::fromUTF8(icu::StringPiece(value.data(), static_cast(value.size()))); + icu::ErrorCode status; + UParseError parseError; + icu::MessageFormat message(pattern, langOrEn, parseError, status); + if (checkSuccess(status, std::string("Failed to create message ") + key + " for locale " + lang.getName(), + parseError)) { - const auto key = it.first.as(); - const auto value = it.second.as(); - icu::UnicodeString pattern = icu::UnicodeString::fromUTF8( - icu::StringPiece(value.data(), static_cast(value.size()))); - icu::ErrorCode status; - UParseError parseError; - icu::MessageFormat message(pattern, langOrEn, parseError, status); - if (checkSuccess(status, - std::string("Failed to create message ") + key + " for locale " + lang.getName(), parseError)) - { - mBundles[localeName].insert(std::make_pair(key, message)); - } + mBundles[localeName].insert(std::make_pair(key, message)); } } - catch (std::exception& e) - { - Log(Debug::Error) << "Can not load " << path << ": " << e.what(); - } } const icu::MessageFormat* MessageBundles::findMessage(std::string_view key, const std::string& localeName) const diff --git a/components/l10n/messagebundles.hpp b/components/l10n/messagebundles.hpp index f3e8f9db19..0ea92e93fe 100644 --- a/components/l10n/messagebundles.hpp +++ b/components/l10n/messagebundles.hpp @@ -40,7 +40,7 @@ namespace l10n const std::vector& args) const; void setPreferredLocales(const std::vector& preferredLocales); const std::vector& getPreferredLocales() const { return mPreferredLocales; } - void load(std::istream& input, const icu::Locale& lang, const std::string& path); + void load(std::istream& input, const icu::Locale& lang); bool isLoaded(const icu::Locale& loc) const { return mBundles.find(loc.getName()) != mBundles.end(); } const icu::Locale& getFallbackLocale() const { return mFallbackLocale; } void setGmstLoader(std::function fn) { mGmstLoader = std::move(fn); }