Fixed a crash when falling back to default dimen values.

This commit is contained in:
casey langen 2018-12-19 17:29:00 -08:00
parent c59ec77358
commit a87c8563c0

View File

@ -168,17 +168,16 @@ std::string Locale::Translate(const char* key) {
int Locale::Dimension(const char* key, int defaultValue) {
if (!this->localeData.is_null()) { /* current locale */
const nlohmann::json& strings = this->localeData.value(KEY_DIMENSIONS, empty);
auto it = strings.find(key);
if (it != strings.end()) {
const nlohmann::json& dimens = this->localeData.value(KEY_DIMENSIONS, empty);
auto it = dimens.find(key);
if (it != dimens.end()) {
return it.value();
}
}
if (!this->defaultLocaleData.is_null()) { /* fall back to default */
const nlohmann::json& strings = this->defaultLocaleData.value(KEY_DIMENSIONS, empty);
auto it = strings.find(key);
return (it != strings.end()) ? it.value() : key;
const nlohmann::json& dimens = this->defaultLocaleData.value(KEY_DIMENSIONS, empty);
return dimens.value(key, defaultValue);
}
return defaultValue; /* not found anywhere */