| 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 """Formats as a .json file that can be used to localize Google Chrome | 6 """Formats as a .json file that can be used to localize Google Chrome |
| 7 extensions.""" | 7 extensions.""" |
| 8 | 8 |
| 9 from json import JSONEncoder | 9 from json import JSONEncoder |
| 10 import re | 10 import re |
| 11 import types | 11 import types |
| 12 | 12 |
| 13 from grit import util | 13 from grit import util |
| 14 from grit.node import message | 14 from grit.node import message |
| 15 | 15 |
| 16 def Format(root, lang='en', output_dir='.'): | 16 def Format(root, lang='en', output_dir='.'): |
| 17 """Format the messages as JSON.""" | 17 """Format the messages as JSON.""" |
| 18 yield '{\n' | 18 yield '{\n' |
| 19 | 19 |
| 20 encoder = JSONEncoder(); | 20 encoder = JSONEncoder(); |
| 21 format = (' "%s": {\n' | 21 format = (' "%s": {\n' |
| 22 ' "message": %s\n' | 22 ' "message": %s\n' |
| 23 ' }') | 23 ' }') |
| 24 first = True | 24 first = True |
| 25 for child in root.ActiveDescendants(): | 25 for child in root.ActiveDescendants(): |
| 26 if isinstance(child, message.MessageNode): | 26 if isinstance(child, message.MessageNode): |
| 27 id = child.attrs['name'] | 27 id = child.attrs['name'] |
| 28 if id.startswith('IDR_'): | 28 if id.startswith('IDR_') or id.startswith('IDS_'): |
| 29 id = id[4:] | 29 id = id[4:] |
| 30 | 30 |
| 31 loc_message = encoder.encode(child.Translate(lang)) | 31 loc_message = encoder.encode(child.Translate(lang)) |
| 32 | 32 |
| 33 if not first: | 33 if not first: |
| 34 yield ',\n' | 34 yield ',\n' |
| 35 first = False | 35 first = False |
| 36 yield format % (id, loc_message) | 36 yield format % (id, loc_message) |
| 37 | 37 |
| 38 yield '\n}\n' | 38 yield '\n}\n' |
| OLD | NEW |