mirror of
https://gh.llkk.cc/https://github.com/WeblateOrg/language-data.git
synced 2025-10-04 15:12:29 +08:00
Style: Improve scripts coding style
Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
parent
a6e907e3d8
commit
1419641401
2 changed files with 42 additions and 43 deletions
|
@ -7,41 +7,7 @@ import json
|
|||
import re
|
||||
|
||||
BASE = "modules/cldr-localenames-full/main/en/languages.json"
|
||||
|
||||
def extract_names(date):
|
||||
for code, langs in data["main"].items():
|
||||
return code, langs["localeDisplayNames"]["languages"]
|
||||
|
||||
# Parse language names
|
||||
with open(BASE, 'r') as handle:
|
||||
data = json.load(handle)
|
||||
names = extract_names(data)[1]
|
||||
|
||||
# Process translations
|
||||
for lang in glob.glob("modules/cldr-localenames-full/main/*/languages.json"):
|
||||
if lang == BASE:
|
||||
continue
|
||||
|
||||
with open(lang, 'r') as handle:
|
||||
data = json.load(handle)
|
||||
|
||||
result = {}
|
||||
|
||||
language_code, language_names = extract_names(data)
|
||||
|
||||
for code, name in language_names.items():
|
||||
if code == name or code not in names:
|
||||
continue
|
||||
name_tokens = set(re.findall(r"\w+", name))
|
||||
code_tokens = set(code.split('-alt')[0].split('-'))
|
||||
if name_tokens & code_tokens:
|
||||
continue
|
||||
|
||||
result[names[code]] = name
|
||||
|
||||
with open("languages-po/{}.po".format(language_code), "w") as handle:
|
||||
handle.write(
|
||||
"""# CLDR language names for {0}
|
||||
HEADER = """# CLDR language names for {0}
|
||||
# Automatically generated using tools available at
|
||||
# https://github.com/WeblateOrg/language-data
|
||||
|
||||
|
@ -54,12 +20,46 @@ msgstr ""
|
|||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"X-Generator: Weblate\\n"
|
||||
|
||||
""".format(language_code)
|
||||
)
|
||||
for msgid, msgstr in sorted(result.items()):
|
||||
handle.write(
|
||||
"""
|
||||
"""
|
||||
ROW = """
|
||||
msgid "{}"
|
||||
msgstr "{}"
|
||||
""".format(msgid, msgstr)
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
def extract_names(date):
|
||||
for code, langs in data["main"].items():
|
||||
return code, langs["localeDisplayNames"]["languages"]
|
||||
|
||||
|
||||
# Parse language names
|
||||
with open(BASE, "r") as handle:
|
||||
data = json.load(handle)
|
||||
names = extract_names(data)[1]
|
||||
|
||||
# Process translations
|
||||
for lang in glob.glob("modules/cldr-localenames-full/main/*/languages.json"):
|
||||
if lang == BASE:
|
||||
continue
|
||||
|
||||
with open(lang, "r") as handle:
|
||||
data = json.load(handle)
|
||||
|
||||
result = {}
|
||||
|
||||
language_code, language_names = extract_names(data)
|
||||
|
||||
for code, name in language_names.items():
|
||||
if code == name or code not in names:
|
||||
continue
|
||||
name_tokens = set(re.findall(r"\w+", name))
|
||||
code_tokens = set(code.split("-alt")[0].split("-"))
|
||||
if name_tokens & code_tokens:
|
||||
continue
|
||||
|
||||
result[names[code]] = name
|
||||
|
||||
with open("languages-po/{}.po".format(language_code), "w") as handle:
|
||||
handle.write(HEADER.format(language_code))
|
||||
for msgid, msgstr in sorted(result.items()):
|
||||
handle.write(ROW.format(msgid, msgstr))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
names = {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue