OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 GRD resource files define all the strings used by a given | 6 """Verifies that GRD resource files define all the strings used by a given |
7 set of source files. For file formats where it is not possible to infer which | 7 set of source files. For file formats where it is not possible to infer which |
8 strings represent message identifiers, localized strings should be explicitly | 8 strings represent message identifiers, localized strings should be explicitly |
9 annotated with the string "i18n-content", for example: | 9 annotated with the string "i18n-content", for example: |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 elif file_type == 'cc': | 65 elif file_type == 'cc': |
66 # C++ style | 66 # C++ style |
67 m = re.search('IDR_([A-Z0-9_]*)', line) | 67 m = re.search('IDR_([A-Z0-9_]*)', line) |
68 if m: return m.group(1) | 68 if m: return m.group(1) |
69 m = re.search('/\*i18n-content\*/["]([^\`"]*)["]', line) | 69 m = re.search('/\*i18n-content\*/["]([^\`"]*)["]', line) |
70 if m: return m.group(1) | 70 if m: return m.group(1) |
71 elif file_type == 'json': | 71 elif file_type == 'json': |
72 # Manifest style | 72 # Manifest style |
73 m = re.search('__MSG_(.*)__', line) | 73 m = re.search('__MSG_(.*)__', line) |
74 if m: return m.group(1) | 74 if m: return m.group(1) |
| 75 elif file_type == 'jinja2': |
| 76 # Jinja2 template file |
| 77 m = re.search('\{\%\s+trans\s+\%\}([A-Z0-9_]+)\{\%\s+endtrans\s+\%\}', line) |
| 78 if m: return m.group(1) |
75 return None | 79 return None |
76 | 80 |
77 | 81 |
78 def VerifyFile(filename, messages, used_tags): | 82 def VerifyFile(filename, messages, used_tags): |
79 """ | 83 """ |
80 Parse |filename|, looking for tags and report any that are not included in | 84 Parse |filename|, looking for tags and report any that are not included in |
81 |messages|. Return True if all tags are present and correct, or False if | 85 |messages|. Return True if all tags are present and correct, or False if |
82 any are missing. If no tags are found, print a warning message and return | 86 any are missing. If no tags are found, print a warning message and return |
83 True. | 87 True. |
84 """ | 88 """ |
85 | 89 |
86 base_name, extension = os.path.splitext(filename) | 90 base_name, extension = os.path.splitext(filename) |
87 extension = extension[1:] | 91 extension = extension[1:] |
88 if extension not in ['js', 'cc', 'html', 'json']: | 92 if extension not in ['js', 'cc', 'html', 'json', 'jinja2']: |
89 raise Exception("Unknown file type: %s" % extension) | 93 raise Exception("Unknown file type: %s" % extension) |
90 | 94 |
91 result = True | 95 result = True |
92 matches = False | 96 matches = False |
93 f = open(filename, 'r') | 97 f = open(filename, 'r') |
94 lines = f.readlines() | 98 lines = f.readlines() |
95 for i in xrange(0, len(lines)): | 99 for i in xrange(0, len(lines)): |
96 tag = ExtractTagFromLine(extension, lines[i]) | 100 tag = ExtractTagFromLine(extension, lines[i]) |
97 if tag: | 101 if tag: |
98 tag = tag.upper() | 102 tag = tag.upper() |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if exit_code == 0: | 150 if exit_code == 0: |
147 f = open(options.touch, 'a') | 151 f = open(options.touch, 'a') |
148 f.close() | 152 f.close() |
149 os.utime(options.touch, None) | 153 os.utime(options.touch, None) |
150 | 154 |
151 return exit_code | 155 return exit_code |
152 | 156 |
153 | 157 |
154 if __name__ == '__main__': | 158 if __name__ == '__main__': |
155 sys.exit(main()) | 159 sys.exit(main()) |
OLD | NEW |