| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Verifies that the message tags in the 2nd and subsequent JSON message files | 6 """Verifies that the message tags in the 2nd and subsequent JSON message files |
| 7 match those specified in the first. This is typically run when the | 7 match those specified in the first. |
| 8 translations are updated before a release, to check that nothing got missed. | 8 |
| 9 This is typically run when the translations are updated before a release, to |
| 10 check that nothing got missed. |
| 9 """ | 11 """ |
| 10 | 12 |
| 11 import json | 13 import json |
| 12 import sys | 14 import sys |
| 13 import string | 15 import string |
| 14 | 16 |
| 15 def CheckTranslation(filename, translation, messages): | 17 def CheckTranslation(filename, translation, messages): |
| 16 """Check |messages| for missing Ids in |translation|, and similarly for unused | 18 """Check |messages| for missing Ids in |translation|, and similarly for unused |
| 17 Ids. If there are missing/unused Ids then report them and return failure. | 19 Ids. If there are missing/unused Ids then report them and return failure. |
| 18 """ | 20 """ |
| 19 message_tags = set(map(string.lower, messages.keys())) | 21 message_tags = set(map(string.lower, messages.keys())) |
| 20 translation_tags = set(map(string.lower, translation.keys())) | 22 translation_tags = set(map(string.lower, translation.keys())) |
| 21 if message_tags == translation_tags: | 23 if message_tags == translation_tags: |
| 22 return True | 24 return True |
| 23 | 25 |
| 24 undefined_tags = message_tags - translation_tags | 26 undefined_tags = message_tags - translation_tags |
| 25 if undefined_tags: | 27 if undefined_tags: |
| 26 print '%s: Missing: %s' % (filename, ", ".join(undefined_tags)) | 28 print '%s: Missing: %s' % (filename, ", ".join(undefined_tags)) |
| 27 | 29 |
| 28 unused_tags = translation_tags - message_tags | 30 unused_tags = translation_tags - message_tags |
| 29 if unused_tags: | 31 if unused_tags: |
| 30 print '%s: Unused: %s' % (filename, ", ".join(unused_tags)) | 32 print '%s: Unused: %s' % (filename, ", ".join(unused_tags)) |
| 31 | 33 |
| 32 return False | 34 return False |
| 33 | 35 |
| 36 |
| 34 def main(): | 37 def main(): |
| 35 if len(sys.argv) < 3: | 38 if len(sys.argv) < 3: |
| 36 print 'Usage: verify-translations.py <messages> <translation-files...>' | 39 print 'Usage: verify-translations.py <messages> <translation-files...>' |
| 37 sys.exit(1) | 40 return 1 |
| 38 | 41 |
| 39 en_messages = json.load(open(sys.argv[1], 'r')) | 42 en_messages = json.load(open(sys.argv[1], 'r')) |
| 40 exit_code = 0 | 43 exit_code = 0 |
| 41 for f in sys.argv[2:]: | 44 for f in sys.argv[2:]: |
| 42 translation = json.load(open(f, 'r')) | 45 translation = json.load(open(f, 'r')) |
| 43 if not CheckTranslation(f, translation, en_messages): | 46 if not CheckTranslation(f, translation, en_messages): |
| 44 exit_code = 1 | 47 exit_code = 1 |
| 45 | 48 |
| 46 sys.exit(exit_code) | 49 return exit_code |
| 50 |
| 47 | 51 |
| 48 if __name__ == '__main__': | 52 if __name__ == '__main__': |
| 49 main() | 53 sys.exit(main()) |
| OLD | NEW |