Asana / locheck

Validate iOS, Android, and Mac localizations. Find errors in .strings, .stringsdict, and strings.xml files.
MIT License
97 stars 11 forks source link

Most of the logic for validating stringsdict #5

Closed stevelandeyasana closed 2 years ago

stevelandeyasana commented 2 years ago

1. Parsing and grammar

Parses strings like Hello %#@bob@ into lists of enums like [.constant("Hello "), .variable("bob")] stored on LexedStringsdictString objects. (Open to suggestions for the name.)

It then uses a basic recursive function to walk the grammar formed by the stringsdict entry's format key and rules to generate all possible permutations.

Example input:

transportation:
  format key: "%#@cars@ and %#@motorcycles@"
  cars:
    one: "one car"
    other: "%1$d cars"
  motorcycles:
    one: "one motorcycle with %#@sidecars@"
    other: "%2$d motorcycle with %#@sidecars@"
  sidecars:
    zero: "no sidecar"
    one: "one sidecar"
    other: "%3$d sidecars"

Example output:

[
 "one car and one motorcycle with no sidecar",
 "one car and one motorcycle with one sidecar",
 "one car and one motorcycle with %3$d sidecars",
 "one car and %2$d motorcycles with no sidecar",
 "one car and %2$d motorcycles with one sidecar",
 "one car and %2$d motorcycles with %3$d sidecars",
 "%1$d cars and one motorcycle with no sidecar",
 "%1$d cars and one motorcycle with one sidecar",
 "%1$d cars and one motorcycle with %3$d sidecars",
 "%1$d cars and %2$d motorcycles with no sidecar",
 "%1$d cars and %2$d motorcycles with one sidecar",
 "%1$d cars and %2$d motorcycles with %3$d sidecars",
]

2. Canonical argument list

Parses all permutations to find arguments, then makes sure each argument at each position has a specifier matching the other permutations.

stevelandeyasana commented 2 years ago

Updated to include internal validation of each entry.

stevelandeyasana commented 2 years ago

I've done a bunch of work since this to redo how errors are logged and to fix bugs. I'll apply any feedback to the followup PR which finishes the work.