X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=scripts%2Fupdate-language-subtags;h=eb5d01e84a2edbd6da9173de7f57e50f68517ec4;hb=c6ecd736091b4597a331dfabcb60bb5aa6083e3a;hp=5990085e81a765df33ab599e3b9be4ca0f2da3a4;hpb=f3e69079eefa18407b110ff23df26f7711ebf7e5;p=libdcp.git diff --git a/scripts/update-language-subtags b/scripts/update-language-subtags index 5990085e..eb5d01e8 100755 --- a/scripts/update-language-subtags +++ b/scripts/update-language-subtags @@ -1,6 +1,8 @@ #!/usr/bin/python3 +import os import urllib.request +import json block = {} lists = {} @@ -8,7 +10,7 @@ lists = {} with urllib.request.urlopen('https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry') as f: #with open('language-subtag-registry', 'r') as f: for l in f.readlines(): - if l.strip().decode('utf-8') == "%%": + if l.strip() == "%%": if 'Type' in block: if block['Type'] in ['language', 'variant', 'region', 'script', 'extlang']: if not block['Type'] in lists: @@ -21,18 +23,25 @@ with urllib.request.urlopen('https://www.iana.org/assignments/language-subtag-re print("Unknown type `%s'" % block['Type']) block = {} else: - p = l.strip().decode('utf-8').split(':') + p = l.strip().split(':') if len(p) > 1: - block[p[0]] = p[1][1:] - -def escape(s): - return s.replace('"', '\\"') + key = p[0] + value = p[1][1:] + if key == 'Description' and key in block: + block[key] = '/'.join([block[key], value]) + else: + block[key] = value -with open('src/language_tag_lists.cc', 'w') as f: - for k, v in lists.items(): - print("static LanguageTag::SubtagData const %s_list[] = {" % k, file=f) +for k, v in lists.items(): + with open(os.path.join('tags', k), 'w') as f: for e in v: - print('\t{ "%s", "%s" },' % (escape(e[0]), escape(e[1])), file=f) - print("};", file=f) - print("", file=f) + print(e[0], file=f) + print(e[1], file=f) + +with urllib.request.urlopen('https://registry.isdcf.com/languages') as f, open(os.path.join('tags', 'dcnc'), 'w') as g: + js = json.loads(f.read()) + for d in js['data']: + if 'dcncTag' in d: + print(d['rfc5646Tag'], file=g) + print(d['dcncTag'], file=g)