scelis / twine

Twine is a command line tool for managing your strings and their translations.
Other
840 stars 151 forks source link

gettext (django) parameters are not format-converted when importing #287

Closed anentropic closed 5 years ago

anentropic commented 5 years ago

If I start with django.po file containing entries like:

#: path/to/file.py:209
#, python-format
msgid "Look what I just bought on %(app_name)s "
msgstr "Guarda un po' che cosa ho appena comperato su %(app_name)s. "

twine consume-all-localization-files imports this as:

[Look what I just bought on %(app_name)s ]
    it = `Guarda un po' che cosa ho appena comperato su %(app_name)s. `

Twine docs say:

Twine supports printf style placeholders with one peculiarity: @ is used for strings instead of s.

...so I don't think this is valid.

And outputs to Android as:

<string name="Look what I just bought on %(app_name)s ">Guarda un po\' che cosa ho appena comperato su %(app_name)s.\u0020</string>

and iOS as:

"Look what I just bought on %(app_name)s " = "Guarda un po' che cosa ho appena comperato su %(app_name)s. ";

I am pretty sure that neither iOS nor Android supports %(app_name)s as a string substitution format, so these are invalid. https://developer.android.com/reference/java/util/Formatter.html https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html#//apple_ref/doc/uid/20000943

Reading more in the Android and Apple docs it seems like they only support index-based string formatting(?). This will make it harder to convert django .po files which routinely contain python-format and python-brace-format (ie values substituted by named arg via dictionary/hashmap) as supported by gettext.

If it's not possible the consume-all-localization-files script should warn that the result will be invalid and needs hand-editing, or just bail out.