twine icon indicating copy to clipboard operation
twine copied to clipboard

Revisit invalid character reporting in validate-strings-file

Open scelis opened this issue 7 years ago • 3 comments

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:

  1. Get a list of valid / invalid characters for all formatters.
  2. Update validate-strings-file for a common set of characters.
  3. 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.

scelis avatar Nov 26 '17 18:11 scelis

  • [ ] 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
    • [ ] Django
    • [ ] Flash
    • [ ] Gettext
    • [ ] jQuery
    • [ ] Tizen
  • [ ] Update validate-strings-file to only allow characters that are valid for all formatters
  • [ ] Honor --format option in validate_twine_file

sebastianludwig avatar Dec 12 '17 16:12 sebastianludwig

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 avatar Dec 12 '17 17:12 sebastianludwig

@sebastianludwig That sounds good to me! Thanks for looking into Android & iOS.

scelis avatar Dec 30 '17 21:12 scelis