OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Formats as a .json file that can be used to localize Google Chrome |
| 7 extensions.""" |
| 8 |
| 9 import re |
| 10 import types |
| 11 |
| 12 from grit import util |
| 13 from grit.format import interface |
| 14 from grit.node import message |
| 15 |
| 16 class StringTable(interface.ItemFormatter): |
| 17 """Writes out the string table.""" |
| 18 |
| 19 def Format(self, item, lang='en', output_dir='.'): |
| 20 out = [] |
| 21 out.append('{\n') |
| 22 |
| 23 format = (' "%s": {\n' |
| 24 ' "message": "%s"\n' |
| 25 ' }') |
| 26 for child in item.children: |
| 27 if isinstance(child, message.MessageNode): |
| 28 loc_message = child.Translate(lang) |
| 29 loc_message = re.sub(r'\\', r'\\\\', loc_message) |
| 30 loc_message = re.sub(r'"', r'\"', loc_message) |
| 31 |
| 32 id = child.attrs['name'] |
| 33 if id.startswith('IDR_'): |
| 34 id = id[4:] |
| 35 |
| 36 if len(out) > 1: |
| 37 out.append(',\n') |
| 38 out.append(format % (id, loc_message)) |
| 39 |
| 40 out.append('\n}\n') |
| 41 return ''.join(out) |
OLD | NEW |