EmptyEpsilon icon indicating copy to clipboard operation
EmptyEpsilon copied to clipboard

[translation] Scenario categories on server creation screen aren't translated in UI

Open oznogon opened this issue 2 years ago • 4 comments
trafficstars

@muerteFR on Discord:

With all these developments, the scenarios 's categories could be translated?

Categories

oznogon avatar Jan 17 '23 08:01 oznogon

ServerScenarioSelectionScreen():

    for(const auto& category : ScenarioInfo::getCategories())
        category_list->addEntry(category, category);

ScenarioInfo::getCategories():

    for(const auto& info : getScenarios())
    {
        for(auto& category : info.categories)
        {
            if (known_categories.find(category) != known_categories.end())
                continue;
            result.push_back(category);
            known_categories.insert(category);
        }
    }

ScenarioInfo::addKeyValue():

    if (key.lower() == "name")
    {
        name = locale->tr(value);
    }
    else if (key.lower() == "description")
    {
        description = locale->tr(value);
    }
    else if (key.lower() == "author")
    {
        author = value;
    }
    else if (key.lower() == "type" || key.lower() == "category")
    {
        categories.push_back(value);
    }

Categories and authors don't use localized strings when added to the key/value store.

diff --git a/src/scenarioInfo.cpp b/src/scenarioInfo.cpp
index c427e255..daf8a849 100644
--- a/src/scenarioInfo.cpp
+++ b/src/scenarioInfo.cpp
@@ -81,7 +81,7 @@ void ScenarioInfo::addKeyValue(string key, string value)
     }
     else if (key.lower() == "type" || key.lower() == "category")
     {
-        categories.push_back(value);
+        categories.push_back(locale->tr(value));
     }
     else if (key.lower() == "variation" && additional != "")
     {

All scenarios must add translation contexts for this for all languages with translations.

diff --git a/scripts/locale/scenario_00_basic.en.po b/scripts/locale/scenario_00_basic.en.po
index 3b4448cd..953d4ecc 100644
--- a/scripts/locale/scenario_00_basic.en.po
+++ b/scripts/locale/scenario_00_basic.en.po
@@ -2,6 +2,10 @@
 msgid "Basic Battle"
 msgstr ""
 
+# Scenario type/category
+msgid "Basic"
+msgstr ""
+
 # Scenario description
 msgid ""
 "A few random stations are under attack by enemies, with random terrain "
diff --git a/scripts/locale/scenario_00_basic.fr.po b/scripts/locale/scenario_00_basic.fr.po
index 37bca5a5..6368b4e8 100644
--- a/scripts/locale/scenario_00_basic.fr.po
+++ b/scripts/locale/scenario_00_basic.fr.po
@@ -18,6 +18,10 @@ msgstr ""
 msgid "Basic Battle"
 msgstr "Bataille simple"
 
+# Scenario type/category
+msgid "Basic"
+msgstr "Simple"
+
 # Scenario description
 msgid ""
 "A few random stations are under attack by enemies, with random terrain "

If they don't, duplicate categories appear because the list is built with string comparisons:

image

oznogon avatar Jan 17 '23 08:01 oznogon

"All scenarios must add translation contexts for this for all languages with translations."

Only the scenarios or also everything in the "locale" folder? Shiptemplates, tutorials etc.

muerteFR avatar Jan 17 '23 11:01 muerteFR

If the change to store scenario categories in locale data I presented was merged, then all scenarios must also translate the Type or Category metadata, like this:

diff --git a/scripts/locale/scenario_00_basic.en.po b/scripts/locale/scenario_00_basic.en.po
index 3b4448cd..953d4ecc 100644
--- a/scripts/locale/scenario_00_basic.en.po
+++ b/scripts/locale/scenario_00_basic.en.po
@@ -2,6 +2,10 @@
 msgid "Basic Battle"
 msgstr ""
 
+# Scenario type/category
+msgid "Basic"
+msgstr ""
+
 # Scenario description
 msgid ""
 "A few random stations are under attack by enemies, with random terrain "
diff --git a/scripts/locale/scenario_00_basic.fr.po b/scripts/locale/scenario_00_basic.fr.po
index 37bca5a5..6368b4e8 100644
--- a/scripts/locale/scenario_00_basic.fr.po
+++ b/scripts/locale/scenario_00_basic.fr.po
@@ -18,6 +18,10 @@ msgstr ""
 msgid "Basic Battle"
 msgstr "Bataille simple"
 
+# Scenario type/category
+msgid "Basic"
+msgstr "Simple"
+
 # Scenario description
 msgid ""
 "A few random stations are under attack by enemies, with random terrain "

This includes generating locale files for every scenario in every supported UI language and translating the type/category string in all of them. So it is not as simple as patching the category list handling to use type/category metadata from the locale store.

Anyone adding any scenario in any language, even if just for their own games and not for inclusion in this repository, would also have to do this if they want to avoid duplicate type/category entries in all other languages.

To avoid this behavior, we might need a different solution that makes type/category list population not dependent on the same string used for localization. That would require changes that I don't know how to make yet.

oznogon avatar Jan 17 '23 19:01 oznogon

Yeah, the reason I didn't do this yet is because of the duplicated entries then in categories, which I didn't like. I don't have a suggestion for a good fix.

daid avatar Jan 18 '23 11:01 daid