-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_localizations_table
executable file
·26 lines (22 loc) · 1.06 KB
/
update_localizations_table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
from urllib.request import urlopen, Request
import gzip
import re
import json
from pathlib import Path
with urlopen(Request("https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry",
headers={"Accept-Encoding": "gzip"})) as response:
raw = gzip.decompress(response.read()).decode()
date, *items = [re.findall(r"([^\s:]+): *(.*)", i) for i in raw.split("%%")]
compiled = {"language": {}, "region": {}, "modifier": {}}
for item in items:
type_, = (value for (key, value) in item if key == "Type")
description = ", ".join(value for (key, value) in item if key == "Description")
if description == "Private use":
continue
type_ = {"extlang": "language", "script": "modifier", "variant": "modifier"}.get(type_, type_)
if type_ in compiled:
tag, = (value for (key, value) in item if key == "Subtag")
compiled[type_][tag] = description
with Path(__file__, "../polycotylus/localizations.json").resolve().open("w") as f:
json.dump(compiled, f, indent="\t", sort_keys=True)