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