1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-27 06:14:09 +00:00

Use normalized path in l10m manager

This commit is contained in:
elsid 2024-08-18 20:05:11 +02:00
parent 527fa053c5
commit 92a0bbb454
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625
3 changed files with 27 additions and 25 deletions

View File

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

View File

@ -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<std::string>();
const auto value = it.second.as<std::string>();
icu::UnicodeString pattern
= icu::UnicodeString::fromUTF8(icu::StringPiece(value.data(), static_cast<std::int32_t>(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<std::string>();
const auto value = it.second.as<std::string>();
icu::UnicodeString pattern = icu::UnicodeString::fromUTF8(
icu::StringPiece(value.data(), static_cast<std::int32_t>(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

View File

@ -40,7 +40,7 @@ namespace l10n
const std::vector<icu::Formattable>& args) const;
void setPreferredLocales(const std::vector<icu::Locale>& preferredLocales);
const std::vector<icu::Locale>& 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<std::string(std::string_view)> fn) { mGmstLoader = std::move(fn); }