mirror of
https://gh.wpcy.net/https://github.com/WeblateOrg/language-data.git
synced 2026-04-21 09:42:22 +08:00
36 lines
974 B
Python
Executable file
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))
|