|
|
|
@ -77,7 +77,8 @@ namespace l10n
|
|
|
|
|
{
|
|
|
|
|
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::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);
|
|
|
|
@ -115,7 +116,8 @@ namespace l10n
|
|
|
|
|
std::vector<icu::Formattable> argValues;
|
|
|
|
|
for (auto& [k, v] : args)
|
|
|
|
|
{
|
|
|
|
|
argNames.push_back(icu::UnicodeString::fromUTF8(icu::StringPiece(k.data(), static_cast<std::int32_t>(k.size()))));
|
|
|
|
|
argNames.push_back(
|
|
|
|
|
icu::UnicodeString::fromUTF8(icu::StringPiece(k.data(), static_cast<std::int32_t>(k.size()))));
|
|
|
|
|
argValues.push_back(v);
|
|
|
|
|
}
|
|
|
|
|
return formatMessage(key, argNames, argValues);
|
|
|
|
@ -174,13 +176,15 @@ namespace l10n
|
|
|
|
|
}
|
|
|
|
|
UParseError parseError;
|
|
|
|
|
icu::MessageFormat defaultMessage(
|
|
|
|
|
icu::UnicodeString::fromUTF8(icu::StringPiece(key.data(), static_cast<std::int32_t>(key.size()))), defaultLocale, parseError, success);
|
|
|
|
|
icu::UnicodeString::fromUTF8(icu::StringPiece(key.data(), static_cast<std::int32_t>(key.size()))),
|
|
|
|
|
defaultLocale, parseError, success);
|
|
|
|
|
if (!checkSuccess(success, std::string("Failed to create message ") + key.data(), parseError))
|
|
|
|
|
// If we can't parse the key as a pattern, just return the key
|
|
|
|
|
return std::string(key);
|
|
|
|
|
|
|
|
|
|
if (!args.empty() && !argNames.empty())
|
|
|
|
|
defaultMessage.format(argNames.data(), args.data(), static_cast<std::int32_t>(args.size()), result, success);
|
|
|
|
|
defaultMessage.format(
|
|
|
|
|
argNames.data(), args.data(), static_cast<std::int32_t>(args.size()), result, success);
|
|
|
|
|
else
|
|
|
|
|
defaultMessage.format(nullptr, nullptr, static_cast<std::int32_t>(args.size()), result, success);
|
|
|
|
|
checkSuccess(success, std::string("Failed to format message ") + key.data());
|
|
|
|
|