Skip to content

Commit

Permalink
Add a script to compare translations
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Feb 12, 2024
1 parent 3435046 commit 3596250
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dev/release/resources/languages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# generate_characterTable.py

The script generates character lists to generate embedded fonts.

# compare_languages.py

The script compares between languages to check which text exists and doesn't exists.
51 changes: 51 additions & 0 deletions Dev/release/resources/languages/compare_languages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import List, Dict
from pathlib import Path
import csv
import re
import sys

root_path = Path("./")

lang_keywords: List[str] = ["en", "ja", "es", "zhcn"]

key_to_texts: Dict[str, Dict[str, str]] = {}


def get_csv_pathes(lang_keyword: str) -> List[Path]:
tte_le = root_path / lang_keyword
if len(sys.argv) >= 2:
return [tte_le / v for v in sys.argv[1:]]
else:
return list(tte_le.glob("**/*.csv"))


for lang_keyword in lang_keywords:
tte_le = root_path / lang_keyword
csv_pathes = get_csv_pathes(lang_keyword)

for csv_path in csv_pathes:
relative_path = csv_path.relative_to(tte_le)
relative_path_key = str(relative_path).replace("\\", "/")

print(f"other {relative_path}")
with open(csv_path, encoding="utf-8") as f:
reader = csv.reader(f)
for row in reader:
if len(row) == 0 or row[0] == "":
continue
key = f"{relative_path_key}@{row[0]}"
if not (key in key_to_texts.keys()):
key_to_texts[key] = {}
key_to_texts[key][lang_keyword] = row[1]

with open("result_compare.csv", "w", encoding="utf-8") as f:
writer = csv.writer(f, lineterminator="\n")
writer.writerow([""] + lang_keywords)
for (key, text) in key_to_texts.items():
row = [key]
for lang_keyword in lang_keywords:
if lang_keyword in text.keys():
row.append(text[lang_keyword])
else:
row.append("!!!None!!!")
writer.writerow(row)

0 comments on commit 3596250

Please sign in to comment.