mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-16 20:15:38 +00:00
Added localization support to the label entries in capabilities.xml
This commit is contained in:
parent
2446e9d91c
commit
18eade57ad
|
@ -230,7 +230,14 @@ void GuiMenu::openUIOptions()
|
||||||
// If required, abbreviate the variant name so it doesn't overlap the
|
// If required, abbreviate the variant name so it doesn't overlap the
|
||||||
// setting name.
|
// setting name.
|
||||||
const float maxNameLength {mSize.x * 0.62f};
|
const float maxNameLength {mSize.x * 0.62f};
|
||||||
themeVariant->add(Utils::String::toUpper(variant.label), variant.name,
|
std::string label {variant.labels.front().second};
|
||||||
|
for (const auto& labelEntry : variant.labels) {
|
||||||
|
if (labelEntry.first == Utils::Localization::sCurrentLocale) {
|
||||||
|
label = labelEntry.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
themeVariant->add(Utils::String::toUpper(label), variant.name,
|
||||||
variant.name == selectedVariant, maxNameLength);
|
variant.name == selectedVariant, maxNameLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,7 +284,14 @@ void GuiMenu::openUIOptions()
|
||||||
// If required, abbreviate the color scheme name so it doesn't overlap the
|
// If required, abbreviate the color scheme name so it doesn't overlap the
|
||||||
// setting name.
|
// setting name.
|
||||||
const float maxNameLength {mSize.x * 0.52f};
|
const float maxNameLength {mSize.x * 0.52f};
|
||||||
themeColorScheme->add(Utils::String::toUpper(colorScheme.label), colorScheme.name,
|
std::string label {colorScheme.labels.front().second};
|
||||||
|
for (const auto& labelEntry : colorScheme.labels) {
|
||||||
|
if (labelEntry.first == Utils::Localization::sCurrentLocale) {
|
||||||
|
label = labelEntry.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
themeColorScheme->add(Utils::String::toUpper(label), colorScheme.name,
|
||||||
colorScheme.name == selectedColorScheme, maxNameLength);
|
colorScheme.name == selectedColorScheme, maxNameLength);
|
||||||
}
|
}
|
||||||
if (themeColorScheme->getSelectedObjects().size() == 0)
|
if (themeColorScheme->getSelectedObjects().size() == 0)
|
||||||
|
@ -413,10 +427,19 @@ void GuiMenu::openUIOptions()
|
||||||
if (currentSet->second.capabilities.transitions.size() == 1 &&
|
if (currentSet->second.capabilities.transitions.size() == 1 &&
|
||||||
currentSet->second.capabilities.transitions.front().selectable) {
|
currentSet->second.capabilities.transitions.front().selectable) {
|
||||||
std::string label;
|
std::string label;
|
||||||
if (currentSet->second.capabilities.transitions.front().label == "")
|
if (currentSet->second.capabilities.transitions.front().labels.front().second == "") {
|
||||||
label = _("THEME PROFILE");
|
label = _("THEME PROFILE");
|
||||||
else
|
}
|
||||||
label = currentSet->second.capabilities.transitions.front().label;
|
else {
|
||||||
|
label = currentSet->second.capabilities.transitions.front().labels.front().second;
|
||||||
|
for (const auto& labelEntry :
|
||||||
|
currentSet->second.capabilities.transitions.front().labels) {
|
||||||
|
if (labelEntry.first == Utils::Localization::sCurrentLocale) {
|
||||||
|
label = labelEntry.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const std::string transitions {
|
const std::string transitions {
|
||||||
currentSet->second.capabilities.transitions.front().name};
|
currentSet->second.capabilities.transitions.front().name};
|
||||||
themeTransitions->add(Utils::String::toUpper(label), transitions,
|
themeTransitions->add(Utils::String::toUpper(label), transitions,
|
||||||
|
@ -427,10 +450,19 @@ void GuiMenu::openUIOptions()
|
||||||
if (!currentSet->second.capabilities.transitions[i].selectable)
|
if (!currentSet->second.capabilities.transitions[i].selectable)
|
||||||
continue;
|
continue;
|
||||||
std::string label;
|
std::string label;
|
||||||
if (currentSet->second.capabilities.transitions[i].label == "")
|
if (currentSet->second.capabilities.transitions[i].labels.empty()) {
|
||||||
label = _("THEME PROFILE") + " " + std::to_string(i + 1);
|
label = _("THEME PROFILE") + " " + std::to_string(i + 1);
|
||||||
else
|
}
|
||||||
label = currentSet->second.capabilities.transitions[i].label;
|
else {
|
||||||
|
label = currentSet->second.capabilities.transitions[i].labels.front().second;
|
||||||
|
for (const auto& labelEntry :
|
||||||
|
currentSet->second.capabilities.transitions[i].labels) {
|
||||||
|
if (labelEntry.first == Utils::Localization::sCurrentLocale) {
|
||||||
|
label = labelEntry.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const std::string transitions {currentSet->second.capabilities.transitions[i].name};
|
const std::string transitions {currentSet->second.capabilities.transitions[i].name};
|
||||||
themeTransitions->add(Utils::String::toUpper(label), transitions,
|
themeTransitions->add(Utils::String::toUpper(label), transitions,
|
||||||
transitions == selectedThemeTransitions);
|
transitions == selectedThemeTransitions);
|
||||||
|
|
|
@ -1201,23 +1201,53 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string&
|
||||||
readVariant.name = name;
|
readVariant.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pugi::xml_node& labelTag {variant.child("label")};
|
if (variant.child("label") == nullptr) {
|
||||||
if (labelTag == nullptr) {
|
|
||||||
LOG(LogDebug)
|
LOG(LogDebug)
|
||||||
<< "No variant <label> tag found, setting label value to the variant name \""
|
<< "No variant <label> tags found, setting label value to the variant name \""
|
||||||
<< name << "\" for \"" << capFile << "\"";
|
<< name << "\" for \"" << capFile << "\"";
|
||||||
readVariant.label = name;
|
readVariant.labels.emplace_back(std::make_pair("en_US", name));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const std::string& labelValue {labelTag.text().as_string()};
|
std::vector<std::pair<std::string, std::string>> labels;
|
||||||
if (labelValue == "") {
|
for (pugi::xml_node labelTag {variant.child("label")}; labelTag;
|
||||||
LOG(LogWarning) << "No variant <label> value defined, setting value to "
|
labelTag = labelTag.next_sibling("label")) {
|
||||||
"the variant name \""
|
std::string language {labelTag.attribute("language").as_string()};
|
||||||
<< name << "\" for \"" << capFile << "\"";
|
if (language == "")
|
||||||
readVariant.label = name;
|
language = "en_US";
|
||||||
|
else if (std::find_if(sSupportedLanguages.cbegin(), sSupportedLanguages.cend(),
|
||||||
|
[language](std::pair<std::string, std::string> currLang) {
|
||||||
|
return currLang.first == language;
|
||||||
|
}) == sSupportedLanguages.cend()) {
|
||||||
|
LOG(LogWarning) << "Declared language \"" << language
|
||||||
|
<< "\" not supported, setting label language to \"en_US\""
|
||||||
|
" for variant name \""
|
||||||
|
<< name << "\" in \"" << capFile << "\"";
|
||||||
|
language = "en_US";
|
||||||
|
}
|
||||||
|
std::string labelValue {labelTag.text().as_string()};
|
||||||
|
if (labelValue == "") {
|
||||||
|
LOG(LogWarning) << "No variant <label> value defined, setting value to "
|
||||||
|
"the variant name \""
|
||||||
|
<< name << "\" for \"" << capFile << "\"";
|
||||||
|
labelValue = name;
|
||||||
|
}
|
||||||
|
labels.emplace_back(std::make_pair(language, labelValue));
|
||||||
}
|
}
|
||||||
else {
|
if (!labels.empty()) {
|
||||||
readVariant.label = labelValue;
|
// Add the label languages in the order they are defined in sSupportedLanguages.
|
||||||
|
for (auto& language : sSupportedLanguages) {
|
||||||
|
if (language.first == "automatic")
|
||||||
|
continue;
|
||||||
|
const auto it =
|
||||||
|
std::find_if(labels.cbegin(), labels.cend(),
|
||||||
|
[language](std::pair<std::string, std::string> currLabel) {
|
||||||
|
return currLabel.first == language.first;
|
||||||
|
});
|
||||||
|
if (it != labels.cend()) {
|
||||||
|
readVariant.labels.emplace_back(
|
||||||
|
std::make_pair((*it).first, (*it).second));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1347,23 +1377,53 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string&
|
||||||
readColorScheme.name = name;
|
readColorScheme.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pugi::xml_node& labelTag {colorScheme.child("label")};
|
if (colorScheme.child("label") == nullptr) {
|
||||||
if (labelTag == nullptr) {
|
|
||||||
LOG(LogDebug) << "No colorScheme <label> tag found, setting label value to the "
|
LOG(LogDebug) << "No colorScheme <label> tag found, setting label value to the "
|
||||||
"color scheme name \""
|
"color scheme name \""
|
||||||
<< name << "\" for \"" << capFile << "\"";
|
<< name << "\" for \"" << capFile << "\"";
|
||||||
readColorScheme.label = name;
|
readColorScheme.labels.emplace_back(std::make_pair("en_US", name));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const std::string& labelValue {labelTag.text().as_string()};
|
std::vector<std::pair<std::string, std::string>> labels;
|
||||||
if (labelValue == "") {
|
for (pugi::xml_node labelTag {colorScheme.child("label")}; labelTag;
|
||||||
LOG(LogWarning) << "No colorScheme <label> value defined, setting value to "
|
labelTag = labelTag.next_sibling("label")) {
|
||||||
"the color scheme name \""
|
std::string language {labelTag.attribute("language").as_string()};
|
||||||
<< name << "\" for \"" << capFile << "\"";
|
if (language == "")
|
||||||
readColorScheme.label = name;
|
language = "en_US";
|
||||||
|
else if (std::find_if(sSupportedLanguages.cbegin(), sSupportedLanguages.cend(),
|
||||||
|
[language](std::pair<std::string, std::string> currLang) {
|
||||||
|
return currLang.first == language;
|
||||||
|
}) == sSupportedLanguages.cend()) {
|
||||||
|
LOG(LogWarning) << "Declared language \"" << language
|
||||||
|
<< "\" not supported, setting label language to \"en_US\""
|
||||||
|
" for color scheme name \""
|
||||||
|
<< name << "\" in \"" << capFile << "\"";
|
||||||
|
language = "en_US";
|
||||||
|
}
|
||||||
|
std::string labelValue {labelTag.text().as_string()};
|
||||||
|
if (labelValue == "") {
|
||||||
|
LOG(LogWarning) << "No colorScheme <label> value defined, setting value to "
|
||||||
|
"the color scheme name \""
|
||||||
|
<< name << "\" for \"" << capFile << "\"";
|
||||||
|
labelValue = name;
|
||||||
|
}
|
||||||
|
labels.emplace_back(std::make_pair(language, labelValue));
|
||||||
}
|
}
|
||||||
else {
|
if (!labels.empty()) {
|
||||||
readColorScheme.label = labelValue;
|
// Add the label languages in the order they are defined in sSupportedLanguages.
|
||||||
|
for (auto& language : sSupportedLanguages) {
|
||||||
|
if (language.first == "automatic")
|
||||||
|
continue;
|
||||||
|
const auto it =
|
||||||
|
std::find_if(labels.cbegin(), labels.cend(),
|
||||||
|
[language](std::pair<std::string, std::string> currLabel) {
|
||||||
|
return currLabel.first == language.first;
|
||||||
|
});
|
||||||
|
if (it != labels.cend()) {
|
||||||
|
readColorScheme.labels.emplace_back(
|
||||||
|
std::make_pair((*it).first, (*it).second));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1451,10 +1511,6 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string&
|
||||||
if (name == "")
|
if (name == "")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const pugi::xml_node& labelTag {transitions.child("label")};
|
|
||||||
if (labelTag != nullptr)
|
|
||||||
label = labelTag.text().as_string();
|
|
||||||
|
|
||||||
const pugi::xml_node& selectableTag {transitions.child("selectable")};
|
const pugi::xml_node& selectableTag {transitions.child("selectable")};
|
||||||
if (selectableTag != nullptr) {
|
if (selectableTag != nullptr) {
|
||||||
const std::string& value {selectableTag.text().as_string()};
|
const std::string& value {selectableTag.text().as_string()};
|
||||||
|
@ -1524,7 +1580,44 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string&
|
||||||
|
|
||||||
ThemeTransitions transition;
|
ThemeTransitions transition;
|
||||||
transition.name = name;
|
transition.name = name;
|
||||||
transition.label = label;
|
|
||||||
|
std::vector<std::pair<std::string, std::string>> labels;
|
||||||
|
for (pugi::xml_node labelTag {transitions.child("label")}; labelTag;
|
||||||
|
labelTag = labelTag.next_sibling("label")) {
|
||||||
|
std::string language {labelTag.attribute("language").as_string()};
|
||||||
|
if (language == "")
|
||||||
|
language = "en_US";
|
||||||
|
else if (std::find_if(sSupportedLanguages.cbegin(), sSupportedLanguages.cend(),
|
||||||
|
[language](std::pair<std::string, std::string> currLang) {
|
||||||
|
return currLang.first == language;
|
||||||
|
}) == sSupportedLanguages.cend()) {
|
||||||
|
LOG(LogWarning) << "Declared language \"" << language
|
||||||
|
<< "\" not supported, setting label language to \"en_US\""
|
||||||
|
" for transition name \""
|
||||||
|
<< name << "\" in \"" << capFile << "\"";
|
||||||
|
language = "en_US";
|
||||||
|
}
|
||||||
|
std::string labelValue {labelTag.text().as_string()};
|
||||||
|
if (labelValue != "")
|
||||||
|
labels.emplace_back(std::make_pair(language, labelValue));
|
||||||
|
}
|
||||||
|
if (!labels.empty()) {
|
||||||
|
// Add the label languages in the order they are defined in sSupportedLanguages.
|
||||||
|
for (auto& language : sSupportedLanguages) {
|
||||||
|
if (language.first == "automatic")
|
||||||
|
continue;
|
||||||
|
const auto it =
|
||||||
|
std::find_if(labels.cbegin(), labels.cend(),
|
||||||
|
[language](std::pair<std::string, std::string> currLabel) {
|
||||||
|
return currLabel.first == language.first;
|
||||||
|
});
|
||||||
|
if (it != labels.cend()) {
|
||||||
|
transition.labels.emplace_back(
|
||||||
|
std::make_pair((*it).first, (*it).second));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
transition.selectable = selectable;
|
transition.selectable = selectable;
|
||||||
transition.animations = std::move(readTransitions);
|
transition.animations = std::move(readTransitions);
|
||||||
capabilities.transitions.emplace_back(std::move(transition));
|
capabilities.transitions.emplace_back(std::move(transition));
|
||||||
|
@ -1580,8 +1673,7 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string&
|
||||||
// always show up in the same order in the UI Settings menu.
|
// always show up in the same order in the UI Settings menu.
|
||||||
if (!aspectRatiosTemp.empty()) {
|
if (!aspectRatiosTemp.empty()) {
|
||||||
// Add the "automatic" aspect ratio if there is at least one entry.
|
// Add the "automatic" aspect ratio if there is at least one entry.
|
||||||
if (!aspectRatiosTemp.empty())
|
capabilities.aspectRatios.emplace_back(sSupportedAspectRatios.front().first);
|
||||||
capabilities.aspectRatios.emplace_back(sSupportedAspectRatios.front().first);
|
|
||||||
for (auto& aspectRatio : sSupportedAspectRatios) {
|
for (auto& aspectRatio : sSupportedAspectRatios) {
|
||||||
if (std::find(aspectRatiosTemp.cbegin(), aspectRatiosTemp.cend(), aspectRatio.first) !=
|
if (std::find(aspectRatiosTemp.cbegin(), aspectRatiosTemp.cend(), aspectRatio.first) !=
|
||||||
aspectRatiosTemp.cend()) {
|
aspectRatiosTemp.cend()) {
|
||||||
|
@ -1594,8 +1686,7 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string&
|
||||||
// show up in the same order in the UI Settings menu.
|
// show up in the same order in the UI Settings menu.
|
||||||
if (!languagesTemp.empty()) {
|
if (!languagesTemp.empty()) {
|
||||||
// Add the "automatic" language if there is at least one entry.
|
// Add the "automatic" language if there is at least one entry.
|
||||||
if (!languagesTemp.empty())
|
capabilities.languages.emplace_back(sSupportedLanguages.front().first);
|
||||||
capabilities.languages.emplace_back(sSupportedLanguages.front().first);
|
|
||||||
for (auto& language : sSupportedLanguages) {
|
for (auto& language : sSupportedLanguages) {
|
||||||
if (std::find(languagesTemp.cbegin(), languagesTemp.cend(), language.first) !=
|
if (std::find(languagesTemp.cbegin(), languagesTemp.cend(), language.first) !=
|
||||||
languagesTemp.cend()) {
|
languagesTemp.cend()) {
|
||||||
|
|
|
@ -152,7 +152,7 @@ public:
|
||||||
|
|
||||||
struct ThemeVariant {
|
struct ThemeVariant {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string label;
|
std::vector<std::pair<std::string, std::string>> labels;
|
||||||
bool selectable;
|
bool selectable;
|
||||||
std::map<ThemeTriggers::TriggerType, std::pair<std::string, std::vector<std::string>>>
|
std::map<ThemeTriggers::TriggerType, std::pair<std::string, std::vector<std::string>>>
|
||||||
overrides;
|
overrides;
|
||||||
|
@ -165,12 +165,12 @@ public:
|
||||||
|
|
||||||
struct ThemeColorScheme {
|
struct ThemeColorScheme {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string label;
|
std::vector<std::pair<std::string, std::string>> labels;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ThemeTransitions {
|
struct ThemeTransitions {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string label;
|
std::vector<std::pair<std::string, std::string>> labels;
|
||||||
bool selectable;
|
bool selectable;
|
||||||
std::map<ViewTransition, ViewTransitionAnimation> animations;
|
std::map<ViewTransition, ViewTransitionAnimation> animations;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue