mirror of
https://gh.llkk.cc/https://github.com/WeblateOrg/language-data.git
synced 2025-10-04 15:12:29 +08:00
29 lines
833 B
Python
Executable file
29 lines
833 B
Python
Executable file
#! /usr/bin/env python3
|
|
|
|
import json
|
|
import sys
|
|
|
|
names = {}
|
|
|
|
with open("/usr/share/iso-codes/json/iso_639-2.json", "r") as handle:
|
|
for item in json.load(handle)["639-2"]:
|
|
for value in ("alpha_2", "alpha_3"):
|
|
if value in item:
|
|
names[item[value]] = item["name"]
|
|
|
|
with open("/usr/share/iso-codes/json/iso_639-3.json", "r") as handle:
|
|
for item in json.load(handle)["639-3"]:
|
|
for value in ("alpha_2", "alpha_3"):
|
|
if value in item:
|
|
names[item[value]] = item["name"]
|
|
|
|
with open("languages.csv", "r") as handle:
|
|
lines = handle.readlines()
|
|
|
|
for code in sys.argv[1:]:
|
|
lines.append(
|
|
"{};{};{};{}\n".format(code, names[code].split(";")[-1].strip(), 2, "n != 1")
|
|
)
|
|
|
|
with open("languages.csv", "w") as handle:
|
|
handle.writelines(sorted(lines))
|