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.
6 """Formats as a .json file that can be used to localize Google Chrome
9 from json import JSONEncoder
14 from grit.node import message
16 def Format(root, lang='en', output_dir='.'):
17 """Format the messages as JSON."""
20 encoder = JSONEncoder();
21 format = (' "%s": {\n'
25 for child in root.ActiveDescendants():
26 if isinstance(child, message.MessageNode):
27 id = child.attrs['name']
28 if id.startswith('IDR_') or id.startswith('IDS_'):
31 loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) +
37 yield format % (id, loc_message)