Android: Resolving Issue with Formatted Attribute while Translating String Resources

Take a look at the below string

<string name="notifications_talk_page_message" formatted="false">%s left a message on your %s page</string>

The string contains a format parameter, %s which can be replaced by a string value. This innocent looking string resource was a part of a pull request that i submitted to Wikimedia Commons Android app. The changes were tested and finally merged to master. With new string resources in master, translate wiki begin its magic of translating it to over 100 languages that the app currently supports.

The pipeline is setup to auto merge changes from translate wiki to master. The translation of the above string literal led to compilation errors. The problem is that apparently cannot preserve the formatted=”false” attribute.

However, even if supports it, they should be replaced with positional arguments anyway? I think sometimes translation may break the ordering of arguments. Checkout argument_index in by ‘positional arguments’.

The fix for this issue was to do away with the formatted parameter and use positional arguments.

<string name="notifications_talk_page_message">%1$s left a message on your %2$s page</string>

This change had to be made in all the string resource files to fix the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.