-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathexport-cldr-case.py
More file actions
executable file
·54 lines (46 loc) · 1.52 KB
/
export-cldr-case.py
File metadata and controls
executable file
·54 lines (46 loc) · 1.52 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env python3
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: MIT
from __future__ import annotations
import csv
import json
# Read languages
with open("languages.csv") as csvfile:
reader = csv.reader(csvfile, delimiter=",")
next(reader)
LANGUAGE_CODES = {lang[0] for lang in reader}
# Read
with open("case-insensitive.csv") as csvfile:
reader = csv.reader(csvfile, delimiter=",")
next(reader)
CASES = list(reader)
CASE_INSENSITIVE_CODES = {lang[0] for lang in CASES}
# Load CLDR
with open("modules/cldr-json/cldr-json/cldr-core/scriptMetadata.json") as handle:
SCRIPTS = json.load(handle)["scriptMetadata"]
with open(
"modules/cldr-json/cldr-json/cldr-core/supplemental/languageData.json",
) as handle:
LANGUAGES: dict[str, dict[str, str]] = json.load(handle)["supplemental"][
"languageData"
]
base: str
script: str | None
for code in LANGUAGE_CODES:
if "_" in code:
base, script = code.split("_", 1)
else:
base = code
script = None
if script is None or script not in SCRIPTS:
if base in LANGUAGES:
for script in LANGUAGES[base]["_scripts"]:
if SCRIPTS[script]["hasCase"] != "YES":
CASE_INSENSITIVE_CODES.add(base)
elif SCRIPTS[script]["hasCase"] != "YES":
CASE_INSENSITIVE_CODES.add(code)
with open("case-insensitive.csv", "w") as handle:
handle.write("code,\n")
for code in sorted(CASE_INSENSITIVE_CODES):
handle.write(f"{code},\n")