language-data/export-l10n-guide
Michal Čihař 9812558e7d Apply black code formatter
Signed-off-by: Michal Čihař <michal@cihar.com>
2019-04-17 10:56:26 +02:00

31 lines
837 B
Python
Executable file

#! /usr/bin/env python3
# Export Gettext builtin plurals
import re
MATCH = re.compile(r"\s*([^,]+),\s*([^,#]+)( \[#f[0-9]*\]_)?,\s*(nplurals.*)\s*")
with open("modules/l10n-guide/docs/l10n/pluralforms.rst") as handle:
content = handle.read()
output = []
state = 0
for line in content.splitlines():
if "csv-table" in line:
state = 1
continue
if state == 1:
matches = MATCH.match(line)
if matches:
output.append(
"{};{};{};{}\n".format(
matches[1],
matches[2],
int(matches[4].split(";", 1)[0].split("=")[1]),
matches[4].split(";", 1)[1].split("=", 1)[1].rstrip(";"),
)
)
with open("l10n-guide.csv", "w") as handle:
handle.writelines(sorted(output))