Skip to content

Commit 75c8707

Browse files
committed
feat: count 150/419 regions population
1 parent 43bc671 commit 75c8707

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

population.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ el_RO,4174
482482
el_TR,4037
483483
el_UA,7132
484484
en,1728473503
485+
en_150,279594417
486+
en_419,49092422
485487
en_AC,930
486488
en_AE,5016100
487489
en_AG,88265
@@ -639,6 +641,8 @@ en_ZW,7203168
639641
eo,298
640642
eo_SM,298
641643
es,507599381
644+
es_150,69107258
645+
es_419,363966079
642646
es_AD,36709
643647
es_AR,46994400
644648
es_BO,7510320

scripts/export-cldr-population.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,36 @@
66

77
import json
88
from collections import defaultdict
9+
from collections.abc import Generator
910

1011
MAPPING = {
1112
"zh": "zh_Hans",
1213
"pa_Arab": "pa",
1314
}
15+
REGIONS: list[str] = [
16+
"150",
17+
"419",
18+
]
19+
REGION_LANGUAGES: set[str] = {"en", "es"}
20+
21+
with open(
22+
"modules/cldr-json/cldr-json/cldr-core/supplemental/territoryContainment.json",
23+
) as handle:
24+
CONTAINMENT = json.load(handle)["supplemental"]["territoryContainment"]
25+
26+
27+
def get_region_countries(text: str) -> Generator[str]:
28+
for code in CONTAINMENT[text]["_contains"]:
29+
if code.isdigit():
30+
yield from get_region_countries(code)
31+
else:
32+
yield code
33+
34+
35+
REGION_COUNTRIES: dict[str, str] = {}
36+
for code in REGIONS:
37+
for country in get_region_countries(code):
38+
REGION_COUNTRIES[country] = code
1439

1540
with open(
1641
"modules/cldr-json/cldr-json/cldr-core/supplemental/territoryInfo.json",
@@ -26,6 +51,8 @@
2651
factor = float(data["_populationPercent"]) / 100
2752
languages[language] += population * factor
2853
languages[f"{language}_{code}"] += population * factor
54+
if code in REGION_COUNTRIES and language in REGION_LANGUAGES:
55+
languages[f"{language}_{REGION_COUNTRIES[code]}"] += population * factor
2956

3057
with open("population.csv", "w") as handle:
3158
handle.write("code,population\n")

weblate_language_data/population.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
"elx": 0,
196196
"en": 1728473503,
197197
"en@pirate": 1728473503,
198-
"en_150": 0,
198+
"en_150": 279594417,
199199
"en_AU": 25697856,
200200
"en_CA": 33751476,
201201
"en_GB": 67089918,
@@ -215,8 +215,8 @@
215215
"es": 507599381,
216216
"es@formal": 507599381,
217217
"es@informal": 507599381,
218-
"es_150": 0,
219-
"es_419": 0,
218+
"es_150": 69107258,
219+
"es_419": 363966079,
220220
"es_AR": 46994400,
221221
"es_BO": 7510320,
222222
"es_CL": 18291406,

0 commit comments

Comments
 (0)