Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if string resources have set a "formatted" attribute #62

Merged
merged 1 commit into from
Oct 11, 2019

Conversation

BugsBeGone
Copy link
Contributor

@BugsBeGone BugsBeGone commented Oct 8, 2019

Example: <string name="test" formatted="false">100% Success!</string>
This will produce the following in template.pot:

#, c-format
msgctxt "test"
msgid "100% Success!"
msgstr ""

The main purpose of this PR is essentially to negate an erroneously-detected format string if the boolean is set to "false". Also in the unlikely case that a formatted string is not detected, you can force it to use c-format to with the boolean set to "true".

Unfortunately I can't find much in the way of official documentation for anything that actually uses formatted="true|false", but Android Studio certainly knows enough to autocomplete it as a boolean.

Something to note is that this attribute will not be carried over into specific language files (either .po or .xml). Personally I treat the .../res/values-<lc>/strings.xml files as auto-generated, and keep all the clever metadata in the .po files. I can't really see a benefit in explicitly setting the no-c-format gettext flag, but perhaps that will be useful for someone.

@BugsBeGone
Copy link
Contributor Author

It would be nice to also make the auto-detection a bit more robust, but that seems like a bit of a rabbit hole. The SDK platform tools have a linter that tries to do this, and even that is going to catch a lot of false positives (note the comment starting line 816): https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java#799

@miracle2k miracle2k merged commit 744fbf0 into miracle2k:master Oct 11, 2019
miracle2k added a commit that referenced this pull request Oct 11, 2019
Check if string resources have set a "formatted" attribute
@miracle2k
Copy link
Owner

Makes sense, thanks.

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.

None yet

2 participants