language-data/scripts/export-l10n-guide.py

38 lines
997 B
Python
Raw Normal View History

#! /usr/bin/env python3
2023-01-13 09:57:01 +01:00
2023-01-10 09:51:06 +01:00
# Copyright © Michal Čihař <michal@weblate.org>
#
2023-01-13 09:57:01 +01:00
# SPDX-License-Identifier: MIT
2020-11-19 14:26:04 +01:00
"""Export l10n guide 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:
2022-07-14 14:45:50 +02:00
plural_parts = matches[4].split(";")
output.append(
2022-07-14 14:45:50 +02:00
"{},{},{},{}\n".format(
matches[1],
matches[2],
2022-07-14 14:45:50 +02:00
int(plural_parts[0].split("=")[1]),
plural_parts[1].split("=", 1)[1].rstrip(";"),
2025-02-05 14:40:41 +01:00
),
)
with open("l10n-guide.csv", "w") as handle:
2022-07-14 14:45:50 +02:00
handle.write("code,name,nplurals,formula\n")
handle.writelines(sorted(output))