-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automate text direction extracting from CLDR
This fills is the data for all CLDR languages making issues like #1477 less likely to happen.
- Loading branch information
Showing
5 changed files
with
146 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
code | ||
ae | ||
aii | ||
ajp | ||
apc | ||
ar | ||
ar_BH | ||
ar_DZ | ||
ar_EG | ||
ar_KW | ||
ar_LY | ||
ar_MA | ||
ar_SA | ||
ar_YE | ||
ara | ||
arc | ||
ave | ||
bal | ||
bgn | ||
bqi | ||
ckb | ||
ckb_IR | ||
dv | ||
egy | ||
fa | ||
fa_AF | ||
fas | ||
ha | ||
he | ||
heb | ||
khw | ||
ks | ||
lrc | ||
luz | ||
ms_Arab | ||
mzn | ||
nqo | ||
pal | ||
per | ||
phn | ||
ps | ||
rhg | ||
sam | ||
sd | ||
sdh | ||
skr | ||
syc | ||
syr | ||
ug | ||
ur | ||
ur_IN | ||
urd | ||
yi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#! /usr/bin/env python3 | ||
|
||
# Copyright © Michal Čihař <michal@weblate.org> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import json | ||
from pathlib import Path | ||
import csv | ||
|
||
# Read languages | ||
with open("languages.csv") as csvfile: | ||
reader = csv.reader(csvfile, delimiter=",") | ||
next(reader) | ||
LANGUAGES = list(reader) | ||
LANGUAGE_CODES = {lang[0] for lang in LANGUAGES} | ||
|
||
# Read RTL | ||
with open("rtl.csv") as csvfile: | ||
reader = csv.reader(csvfile, delimiter=",") | ||
next(reader) | ||
RTLS = list(reader) | ||
RTL_CODES = {lang[0] for lang in RTLS} | ||
|
||
LAYOUTDIR = Path("modules/cldr-json/cldr-json/cldr-misc-full/main/") | ||
|
||
for layout_file in LAYOUTDIR.glob("*/layout.json"): | ||
json_text = layout_file.read_text() | ||
data = json.loads(json_text) | ||
for key, value in data["main"].items(): | ||
code = key.replace("-", "_") | ||
if code not in LANGUAGE_CODES: | ||
continue | ||
character_order = value["layout"]["orientation"]["characterOrder"] | ||
if character_order == "right-to-left": | ||
RTL_CODES.add(code) | ||
elif character_order != "left-to-right": | ||
print(f"Uknown order for {code}: {character_order})") | ||
|
||
print(RTL_CODES) | ||
|
||
with open("rtl.csv", "w") as handle: | ||
handle.write("code\n") | ||
for code in sorted(RTL_CODES): | ||
handle.write(f"{code}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters