Chromium Code Reviews| 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) | |
|
Jói
2012/10/15 10:31:06
What about \ in the message, do they need to be es
Sergey Ulanov
2012/10/16 00:50:24
That's a good point. I took these two lines from j
| |
| 30 | |
| 31 id = child.attrs['name'] | |
| 32 if id.startswith('IDR_'): | |
| 33 id = id[4:] | |
| 34 | |
| 35 if len(out) > 1: | |
| 36 out.append(',\n') | |
| 37 out.append(format % (id, loc_message)) | |
| 38 | |
| 39 out.append('\n}\n') | |
| 40 return ''.join(out) | |
| OLD | NEW |