language-data/scripts/export-gettext.py
Michal Čihař 3c04fcc193 chore: include extension in scritps filename
This allows to better lint the files.
2025-04-01 09:51:55 +02:00

36 lines
974 B
Python
Executable file

#! /usr/bin/env python3
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: MIT
"""Export Gettext builtin plurals."""
import re
MATCH = re.compile(r'\s*{\s*"([^"]*)",\s*"([^"]*)",\s*"([^"]*)"\s*},?\s*')
with open("modules/gettext/gettext-tools/src/plural-table.c") as handle:
content = handle.read()
output = []
state = 0
for line in content.splitlines():
if "plural_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[3].split(";", 1)[0].split("=")[1]),
matches[3].split(";", 1)[1].split("=", 1)[1].rstrip(";"),
),
)
with open("gettext.csv", "w") as handle:
handle.write("code,name,nplurals,formula\n")
handle.writelines(sorted(output))