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