lutris / agora

Public discussion space for the community
11 stars 0 forks source link

[i18n dev] How to localize the text in JSON runners? #88

Open SwimmingTiger opened 3 years ago

SwimmingTiger commented 3 years ago

It seems that JSON runners currently does not have a localization support, and the text inside cannot be translated.

https://github.com/lutris/lutris/tree/master/share/lutris/json

Is there a way to make localization work for JSON runners?

SwimmingTiger commented 3 years ago

A simple proposal: create a separate JSON file for localization, such as ags-zh_CN.json. But this will bring synchronization disasters: developers may forget to modify all localized versions when modifying a JSON runner, which will eventually result in different content in JSON in different languages.

The following improvements can be made: instead of directly using the localized version, merge its content into the non-localized version. Find the non-localized field corresponding to the localized field and overwrite the value with the localized field.

So if the content of the non-localized version changes, the localized version does not need to be modified immediately. The untranslated content will be presented in English.

The disadvantage of this solution is that the po file cannot be used for JSON runner translation. Localization developers need to manually find the content to be translated.

SwimmingTiger commented 3 years ago

Proposal 2: Write a program to convert the content to be translated in JSON runners into XML. Then you can use meson to process the XML and add the text to be translated into the po file.

In the python code that parses the JSON runner, just call gettext() on the variable to apply the translation.

Or if meson can directly extract the content to be translated from JSON, this would be good news. But this may not be easy, because the content to be translated is also in an unnamed array.

        {
            "option": "filter",
            "type": "choice",
            "label": "Graphics filter (need translate)",
            "choices": [
                ["None (need translate)", "none"],
                ["Standard scaling (need translate)", "stdscale"],
                ["HQ2x (need translate)", "hq2x"],
                ["HQ3x (need translate)", "hq3x"]
            ],
            "argument": "--gfxfilter"
        }
strycore commented 3 years ago

I would just read every label string as translatable. Closer to what you propose in the 2nd solution. I don't know if Meson can extract the strings. It would have to process some rules like: read field "label", read each 1st element of a "choices" array. If Meson has to transform the JSON file to XML, that doesn't seem like a problem, it can be done on the fly. But again, I don't know the capabilities of Meson.

SwimmingTiger commented 3 years ago

I think Meson may not have that ability. A handwritten JSON/XML converter may be required, and then run during the po generation stage.

strycore commented 3 years ago

Writing the code wouldn't be to much of an issue but I'm not sure where to put it or how to invoke it.