8 with urllib.request.urlopen('https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry') as f:
9 #with open('language-subtag-registry', 'r') as f:
10 for l in f.readlines():
11 if l.strip().decode('utf-8') == "%%":
13 if block['Type'] in ['language', 'variant', 'region', 'script', 'extlang']:
14 if not block['Type'] in lists:
15 lists[block['Type']] = []
16 lists[block['Type']].append((block['Subtag'], block['Description']))
17 elif block['Type'] == 'redundant' or block['Type'] == 'grandfathered':
18 # We'll ignore these (for now)
21 print("Unknown type `%s'" % block['Type'])
24 p = l.strip().decode('utf-8').split(':')
26 block[p[0]] = p[1][1:]
29 return s.replace('"', '\\"')
31 with open('src/language_tag_lists.cc', 'w') as f:
32 for k, v in lists.items():
33 print("static LanguageTag::SubtagData %s_list[] = {" % k, file=f)
35 print('\t{ "%s", "%s" },' % (escape(e[0]), escape(e[1])), file=f)