| OLD | NEW |
| (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() |
| OLD | NEW |