Asana / locheck

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

Various improvements to support checking Wikipedia's iOS app #19

Closed stevelandeyasana closed 2 years ago

stevelandeyasana commented 2 years ago

This was a really helpful test case because it revealed some bugs in how we read files.

  1. --ignore-warnings flag. Wikipedia's warnings are all spurious.
  2. Stop trying to do a 1:1 mapping of .strings files. Instead, combine all strings file values into a single list and compare the lists.
  3. Support UTF-16 encoding by retrying file reading if the first read fails with a certain error.
  4. Append problem kind to summary lines to make it easier to ignore specific things.
  5. File-level errors are now reported in the summary instead of only in the line-by-line stderr errors.
  6. Strip common prefix from summary when using discover* commands for readability

Example below. The errors aren't really errors for Wikipedia specifically, but I'm not comfortable downgrading them to warnings without a lot more thought, because these errors would really be errors in the Asana app. Looking at the actual strings, it appears they use a custom localization system, so I'm not worried about it.

> swift run locheck discoverlproj ~/dev/3p/wikipedia-ios/Wikipedia/iOS\ Native\ Localizations --ignore-warnings
Discovering .lproj files in /Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations with en as the base
Source of truth: /Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/en.lproj/
Translations to check: 108
/Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/eu.lproj/Localizable.stringsdict:22: error: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
/Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/eu.lproj/Localizable.stringsdict:166: error: 'reading-lists-delete-reading-list-alert-title' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
/Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/eu.lproj/Localizable.stringsdict:297: error: 'saved-unsave-article-and-remove-from-reading-lists-title' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
/Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/ga.lproj/Localizable.stringsdict:6: error: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
/Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/id.lproj/Localizable.stringsdict:6: error: 'aaald-characters-text-description' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
/Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/nqo.lproj/Localizable.stringsdict:38: error: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
/Users/stevelandey/dev/3p/wikipedia-ios/Wikipedia/iOS Native Localizations/uk.lproj/Localizable.stringsdict:120: error: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)

Summary:
eu.lproj/Localizable.stringsdict
  article-deleted-accessibility-notification:
    ERROR: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
  reading-lists-delete-reading-list-alert-title:
    ERROR: 'reading-lists-delete-reading-list-alert-title' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
  saved-unsave-article-and-remove-from-reading-lists-title:
    ERROR: 'saved-unsave-article-and-remove-from-reading-lists-title' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
ga.lproj/Localizable.stringsdict
  article-deleted-accessibility-notification:
    ERROR: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
id.lproj/Localizable.stringsdict
  aaald-characters-text-description:
    ERROR: 'aaald-characters-text-description' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
nqo.lproj/Localizable.stringsdict
  article-deleted-accessibility-notification:
    ERROR: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
uk.lproj/Localizable.stringsdict
  article-deleted-accessibility-notification:
    ERROR: 'article-deleted-accessibility-notification' has more arguments than the base language. Extra args: d (stringsdict_entry_has_too_many_arguments)
0 warnings, 7 errors
Errors found

Fix #18