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

Side by Side Diff: components/cronet/tools/generate_accept_languages.py

Issue 2665703002: [cronet] Make getAcceptLanguages index a static table instead of the application bundle. (Closed)
Patch Set: move accept_languages header generation script to more appropriate location Created 3 years, 9 months 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
« no previous file with comments | « components/cronet/ios/test/start_cronet.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # This script generates a header containing a dictionary from locales to
6 # accept language strings from chromium's .xtb files. It is not very
7 # robust at the moment, and makes some assumptions about the format of
8 # the files, including at least the following:
9 # * assumes necessary data is contained only with files of the form
10 # components/strings/components_locale_settings_${LANG}.xtb
11 # * assumes ${LANG} is identified in the lang attribute of the root
12 # element of the file's xml data
13 # * assumes that there is only one relevant element with the
14 # IDS_ACCEPT_LANGUAGES attribute
15
16 import os, re, sys
17 from xml.etree import ElementTree
18
19 STRINGS_DIR = sys.argv[2] + 'components/strings/'
20
21 def extract_accept_langs(filename):
22 tree = ElementTree.parse(STRINGS_DIR + filename).getroot()
23 for child in tree:
24 if child.get('id') == 'IDS_ACCEPT_LANGUAGES':
25 return tree.get('lang'), child.text
26
27 def gen_accept_langs_table():
28 return dict(filter(None, (extract_accept_langs(filename)
29 for filename in os.listdir(STRINGS_DIR)
30 if re.match(r'components_locale_settings_\S+.xtb', filename))))
31
32 HEADER = "NSDictionary* acceptLangs = @{"
33 def LINE(locale, accept_langs):
34 return ' @"' + locale + '" : @"' + accept_langs + '",'
35 FOOTER = "};"
36
37 def main():
38 with open(sys.argv[1] + "/accept_languages_table.h", "w+") as f:
39 print >>f, HEADER
40 for (locale, accept_langs) in gen_accept_langs_table().items():
41 print >>f, LINE(locale, accept_langs)
42 print >>f, FOOTER
43
44 if __name__ == "__main__":
45 main()
OLDNEW
« no previous file with comments | « components/cronet/ios/test/start_cronet.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698