mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 19:15:41 +00:00
Merge branch 'vfs_normalized_path_8' into 'master'
Use normalized path for l10n manager See merge request OpenMW/openmw!4329
This commit is contained in:
commit
10419adc58
3 changed files with 27 additions and 25 deletions
|
@ -43,10 +43,19 @@ namespace l10n
|
||||||
path /= name;
|
path /= name;
|
||||||
path /= langName;
|
path /= langName;
|
||||||
|
|
||||||
if (!mVFS->exists(path))
|
const Files::IStreamPtr stream = mVFS->find(path);
|
||||||
|
|
||||||
|
if (stream == nullptr)
|
||||||
return;
|
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)
|
void Manager::updateContext(const std::string& name, MessageBundles& ctx)
|
||||||
|
|
|
@ -66,33 +66,26 @@ namespace l10n
|
||||||
return status.isSuccess();
|
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);
|
const auto key = it.first.as<std::string>();
|
||||||
std::string localeName = lang.getName();
|
const auto value = it.second.as<std::string>();
|
||||||
const icu::Locale& langOrEn = localeName == "gmst" ? icu::Locale::getEnglish() : lang;
|
icu::UnicodeString pattern
|
||||||
for (const auto& it : data)
|
= 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>();
|
mBundles[localeName].insert(std::make_pair(key, message));
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
const icu::MessageFormat* MessageBundles::findMessage(std::string_view key, const std::string& localeName) const
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace l10n
|
||||||
const std::vector<icu::Formattable>& args) const;
|
const std::vector<icu::Formattable>& args) const;
|
||||||
void setPreferredLocales(const std::vector<icu::Locale>& preferredLocales);
|
void setPreferredLocales(const std::vector<icu::Locale>& preferredLocales);
|
||||||
const std::vector<icu::Locale>& getPreferredLocales() const { return mPreferredLocales; }
|
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(); }
|
bool isLoaded(const icu::Locale& loc) const { return mBundles.find(loc.getName()) != mBundles.end(); }
|
||||||
const icu::Locale& getFallbackLocale() const { return mFallbackLocale; }
|
const icu::Locale& getFallbackLocale() const { return mFallbackLocale; }
|
||||||
void setGmstLoader(std::function<std::string(std::string_view)> fn) { mGmstLoader = std::move(fn); }
|
void setGmstLoader(std::function<std::string(std::string_view)> fn) { mGmstLoader = std::move(fn); }
|
||||||
|
|
Loading…
Reference in a new issue