Create functions that call xgettext or msgfmt

This commit is contained in:
Yohann D'ANELLO
2020-11-28 02:54:04 +01:00
parent 7d02604407
commit ffc8b90441
3 changed files with 37 additions and 10 deletions

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import gettext as gt
import subprocess
from typing import Any, List
@ -36,6 +37,32 @@ class Translator:
def get_translator(cls) -> Any:
return cls.translators.get(cls.locale)
@classmethod
def makemessages(cls) -> None:
for language in cls.SUPPORTED_LOCALES:
args = ["find", "squirrelbattle/", "-iname", "*.py"]
find = subprocess.Popen(args, stdout=subprocess.PIPE)
args = ["xargs", "xgettext", "--from-code", "utf-8",
"--join-existing",
"--add-comments",
"--package-name=squirrelbattle",
"--package-version=3.14.1",
"--copyright-holder=ÿnérant, eichhornchen, "
"nicomarg, charlse",
"--msgid-bugs-address=squirrel-battle@crans.org",
"-o", f"locale/{language}/LC_MESSAGES/squirrelbattle.po"]
print(f"Make {language} messages...")
subprocess.Popen(args, stdin=find.stdout)
@classmethod
def compilemessages(cls) -> None:
for language in cls.SUPPORTED_LOCALES:
args = ["msgfmt", "--check-format",
"-o", f"locale/{language}/LC_MESSAGES/squirrelbattle.mo",
f"locale/{language}/LC_MESSAGES/squirrelbattle.po"]
print(f"Compiling {language} messages...")
subprocess.Popen(args)
def gettext(message: str) -> str:
"""