2018-01-26 12:23:03 +01:00
|
|
|
#! /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>
|
2020-09-29 12:59:03 +02:00
|
|
|
#
|
2023-01-13 09:57:01 +01:00
|
|
|
# SPDX-License-Identifier: MIT
|
2018-01-26 12:23:03 +01:00
|
|
|
|
2020-11-19 14:26:04 +01:00
|
|
|
"""Export l10n guide plurals."""
|
2018-01-26 12:23:03 +01:00
|
|
|
|
|
|
|
import re
|
|
|
|
|
2019-04-17 10:56:26 +02:00
|
|
|
MATCH = re.compile(r"\s*([^,]+),\s*([^,#]+)( \[#f[0-9]*\]_)?,\s*(nplurals.*)\s*")
|
2018-01-26 12:23:03 +01:00
|
|
|
|
2019-04-17 10:56:26 +02:00
|
|
|
with open("modules/l10n-guide/docs/l10n/pluralforms.rst") as handle:
|
2018-01-26 12:23:03 +01:00
|
|
|
content = handle.read()
|
|
|
|
|
|
|
|
output = []
|
|
|
|
state = 0
|
|
|
|
for line in content.splitlines():
|
2019-04-17 10:56:26 +02:00
|
|
|
if "csv-table" in line:
|
2018-01-26 12:23:03 +01:00
|
|
|
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(";")
|
2019-04-17 10:56:26 +02:00
|
|
|
output.append(
|
2022-07-14 14:45:50 +02:00
|
|
|
"{},{},{},{}\n".format(
|
2019-04-17 10:56:26 +02:00
|
|
|
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
|
|
|
),
|
2019-04-17 10:56:26 +02:00
|
|
|
)
|
2018-01-26 12:23:03 +01:00
|
|
|
|
2019-04-17 10:56:26 +02:00
|
|
|
with open("l10n-guide.csv", "w") as handle:
|
2022-07-14 14:45:50 +02:00
|
|
|
handle.write("code,name,nplurals,formula\n")
|
2018-01-26 12:23:03 +01:00
|
|
|
handle.writelines(sorted(output))
|