twine
twine copied to clipboard
Revisit invalid character reporting in validate-strings-file
From this comment by @robnadin:
Sorry to comment on up such an old commit, but I'm just wondering why this was changed? As far as I know, aapt automatically converts string names containing dots into underscores, so for example the following key: network.error
will be converted to: R.string.network_error
Our workflow would like to take advantage of using dot syntax so we can generate structured keys for iOS using SwiftGen but keeping the validation of the twine .txt file intact. Currently, running Twine with validation checks spits out numerous Found key(s) with invalid characters: warnings etc.
One consideration we need to maintain is how this affects all formatters, not just Android's.
I would like to propose that we:
- Get a list of valid / invalid characters for all formatters.
- Update
validate-strings-file
for a common set of characters. - Update
validate-strings-file
to support the--format
option to validate the strings file for a particular format. Thus, if--android
is passed in, the Android formatter can provide a list of valid or invalid characters for string keys.
I would love to be able to add support for invalid characters by doing our own replacements (like replace <
with _
when we generate the localization file for a format that does not support <
). However, this adds many complications with consume-localization-file
which may not be worth the complexity and effort.
- [ ] Collect valid key characters for formatters
- [x] Android
- Didn't find an answer in the official Android docs. Apparently the same rules as for Java variables
-
[A-Za-z0-9_$]
with the addition of.
(which will be converted to_
in Java land), but 0-9 aren't allowed as first characters.
- [ ] Apple
- Seems to be printable ASCII (see here and here)
- Needs verification
- [ ] Django
- [ ] Flash
- [ ] Gettext
- [ ] jQuery
- [ ] Tizen
- [x] Android
- [ ] Update
validate-strings-file
to only allow characters that are valid for all formatters - [ ] Honor
--format
option invalidate_twine_file
Finding out the allowed characters is surprisingly painful. Took me an hour to get some information for the two major platforms. Since nobody has complained for the other formatters, how about we use the current character set for the rest (except for Tizen which is identical to Android I guess), @scelis?
@sebastianludwig That sounds good to me! Thanks for looking into Android & iOS.