|
|
|
|
@ -285,46 +285,56 @@ bool ReadEntry(const std::byte *data, size_t dataSize, const MoEntry &e, char *r
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
std::string_view LanguageParticularTranslate(std::string_view context, std::string_view message) |
|
|
|
|
{ |
|
|
|
|
constexpr const char Glue = '\004'; |
|
|
|
|
|
|
|
|
|
std::string key = std::string(context); |
|
|
|
|
std::string_view LanguageParticularTranslate(std::string_view context, std::string_view message) |
|
|
|
|
{ |
|
|
|
|
constexpr const char Glue = '\004'; |
|
|
|
|
|
|
|
|
|
std::string key = std::string(context); |
|
|
|
|
key.reserve(key.size() + 1 + message.size()); |
|
|
|
|
key += Glue; |
|
|
|
|
key.append(message); |
|
|
|
|
|
|
|
|
|
auto it = translation[0].find(key.c_str()); |
|
|
|
|
if (it == translation[0].end()) { |
|
|
|
|
return message; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return GetTranslation(it->second); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string_view LanguagePluralTranslate(const char *singular, std::string_view plural, int count) |
|
|
|
|
{ |
|
|
|
|
const int n = GetLocalPluralId(count); |
|
|
|
|
|
|
|
|
|
auto it = translation[n].find(singular); |
|
|
|
|
if (it == translation[n].end()) { |
|
|
|
|
if (count != 1) |
|
|
|
|
return plural; |
|
|
|
|
return singular; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return GetTranslation(it->second); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string_view LanguageTranslate(const char *key) |
|
|
|
|
{ |
|
|
|
|
auto it = translation[0].find(key); |
|
|
|
|
if (it == translation[0].end()) { |
|
|
|
|
return key; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return GetTranslation(it->second); |
|
|
|
|
} |
|
|
|
|
auto it = translation[0].find(key.c_str()); |
|
|
|
|
if (it == translation[0].end()) { |
|
|
|
|
return message; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const std::string_view translated = GetTranslation(it->second); |
|
|
|
|
// Treat empty translations as missing (prevents invisible UI entries / silent screen reader output).
|
|
|
|
|
return translated.empty() ? message : translated; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string_view LanguagePluralTranslate(const char *singular, std::string_view plural, int count) |
|
|
|
|
{ |
|
|
|
|
const int n = GetLocalPluralId(count); |
|
|
|
|
|
|
|
|
|
auto it = translation[n].find(singular); |
|
|
|
|
if (it == translation[n].end()) { |
|
|
|
|
if (count != 1) |
|
|
|
|
return plural; |
|
|
|
|
return singular; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const std::string_view translated = GetTranslation(it->second); |
|
|
|
|
if (!translated.empty()) |
|
|
|
|
return translated; |
|
|
|
|
// Treat empty translations as missing.
|
|
|
|
|
if (count != 1) |
|
|
|
|
return plural; |
|
|
|
|
return singular; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string_view LanguageTranslate(const char *key) |
|
|
|
|
{ |
|
|
|
|
auto it = translation[0].find(key); |
|
|
|
|
if (it == translation[0].end()) { |
|
|
|
|
return key; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const std::string_view translated = GetTranslation(it->second); |
|
|
|
|
// Treat empty translations as missing.
|
|
|
|
|
return translated.empty() ? std::string_view(key) : translated; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool HasTranslation(const std::string &locale) |
|
|
|
|
{ |
|
|
|
|
|