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
4 # found in the LICENSE file.
6 """Verifies that the message tags in the 2nd and subsequent JSON message files
7 match those specified in the first.
9 This is typically run when the translations are updated before a release, to
10 check that nothing got missed.
17 def CheckTranslation(filename
, translation
, messages
):
18 """Check |messages| for missing Ids in |translation|, and similarly for unused
19 Ids. If there are missing/unused Ids then report them and return failure.
21 message_tags
= set(map(string
.lower
, messages
.keys()))
22 translation_tags
= set(map(string
.lower
, translation
.keys()))
23 if message_tags
== translation_tags
:
26 undefined_tags
= message_tags
- translation_tags
28 print '%s: Missing: %s' % (filename
, ", ".join(undefined_tags
))
30 unused_tags
= translation_tags
- message_tags
32 print '%s: Unused: %s' % (filename
, ", ".join(unused_tags
))
39 print 'Usage: verify-translations.py <messages> <translation-files...>'
42 en_messages
= json
.load(open(sys
.argv
[1], 'r'))
44 for f
in sys
.argv
[2:]:
45 translation
= json
.load(open(f
, 'r'))
46 if not CheckTranslation(f
, translation
, en_messages
):
52 if __name__
== '__main__':