KEMBAR78
I18N: Add script to generate translated android strings.xml, automatically generates fake cpp file by ankushdutt · Pull Request #4831 · scummvm/scummvm · GitHub
Skip to content

Conversation

@ankushdutt
Copy link
Member

@ankushdutt ankushdutt commented Mar 22, 2023

Description

Fixes: https://trello.com/c/EiKn4pYx/36-error-warning-and-info-messages-in-stringsxml-should-be-translate-able-via-the-weblate

This PR adds a python script that generates the translated strings.xml as per this specs: https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources

Also, this script automatically generates the fake cpp for the gettext (to make it translatable for weblate) using res/values/strings.xml.

Relevant translated strings.xml file will be automatically used based on the android system's language.

Testing

For testing, I manually added the string for the permission denied toast in the original and some generated XML (I also edited the relevant code to use string resource instead), and it works as expected.

Here are some screenshots of the android app:

Default:
Default

Using Catalan system's language (same build):
ca

Using Japanese system's language (same build):
ja

@lephilousophe
Copy link
Member

Wouldn't it better to modify weblate configuration? (using https://docs.weblate.org/en/latest/formats.html#aresource)
If something is changed, it has to be in the CPP file which will never be modified using Android Studio.
This looks really fragile.

@ankushdutt
Copy link
Member Author

ankushdutt commented Mar 22, 2023

Wouldn't it better to modify weblate configuration? (using https://docs.weblate.org/en/latest/formats.html#aresource) If something is changed, it has to be in the CPP file which will never be modified using Android Studio. This looks really fragile.

Yes, this makes sense - was trying to implement this approach from discord
Thanks, modifying weblate configuration to also support Android string resources makes more sense - I'm looking into it.

@sev-
Copy link
Member

sev- commented Mar 22, 2023

@lephilousophe, the idea was similar to this PR: #4826

E.g. we turn the strings.xml into a generated file and the original will sit in a Python script. That script will merge in translations from the Weblate.

Unless, of course, you have an idea of how we can mark up the strings.xml file in a way that the gettext utility is happy about it and able to extract/merge back strings

@ankushdutt ankushdutt marked this pull request as draft March 22, 2023 18:21
@ankushdutt ankushdutt marked this pull request as ready for review March 24, 2023 21:46
@ankushdutt ankushdutt changed the title I18N: Add dummy cpp file to make android strings.xml translatable I18N: Add script to generate translated android strings.xml, automatically generates fake cpp file to make strings from values/strings.xml translatable Mar 24, 2023
@ankushdutt ankushdutt changed the title I18N: Add script to generate translated android strings.xml, automatically generates fake cpp file to make strings from values/strings.xml translatable I18N: Add script to generate translated android strings.xml, automatically generates fake cpp file Mar 24, 2023
@sev-
Copy link
Member

sev- commented Apr 9, 2023

@ankushdutt do you intend to follow out commit guidelines?

- Add a python script (generate-android-i18n-strings.py)
 that generates the translated android strings.xml as per:
 https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources
 It considers the dists/android/res/values/strings.xml file as
 a base template to generate those translated strings.xml files.

- The python script also generates a fake cpp with strings from
 dists/android/res/values/strings.xml. These strings will be picked
 up by gettext to make it translatable. If there is any change in the
 original strings.xml file, we won't have to worry about the changes
 in cpp file.

- Add documentation for the generate-android-i18n-strings.py script
@ankushdutt ankushdutt force-pushed the make-strings-translatable branch from 3e0529a to eafe807 Compare April 9, 2023 12:55
@ankushdutt
Copy link
Member Author

@ankushdutt do you intend to follow out commit guidelines?

Sorry yes, I have now squashed the commits with an updated commit message.

@sev-
Copy link
Member

sev- commented May 14, 2023

Okay, rebasing and merging this

@sev- sev- merged commit 74dff32 into scummvm:master May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants