Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: grit/format/chrome_messages_json.py

Issue 1410023007: Skip missing translations when generating JSON resources. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 10 matching lines...) Expand all
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_') or id.startswith('IDS_'): 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.ws_at_start + child.Translate(lang) + 31 cliques = child.GetCliques()
32 child.ws_at_end) 32 assert cliques
33 translation = cliques[0].MessageForLanguage(
34 lang, pseudo_if_no_match=child.PseudoIsAllowed(),
35 fallback_to_english=False, none_if_no_match=True)
36
37 # Skip the string if it's not translated.
38 if translation == None:
Jamie 2015/10/27 19:25:13 Prefer "translation is not None" (https://google-s
Sergey Ulanov 2016/02/06 01:03:17 Done.
39 continue;
40
41 loc_message = encoder.encode(
42 child.ws_at_start + translation.GetRealContent() + child.ws_at_end)
33 43
34 if not first: 44 if not first:
35 yield ',\n' 45 yield ',\n'
36 first = False 46 first = False
37 yield format % (id, loc_message) 47 yield format % (id, loc_message)
38 48
39 yield '\n}\n' 49 yield '\n}\n'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698