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

@ -1,14 +1,14 @@
# SOME DESCRIPTIVE TITLE. # SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # Copyright (C) YEAR ÿnérant, eichhornchen, nicomarg, charlse
# This file is distributed under the same license as the PACKAGE package. # This file is distributed under the same license as the squirrelbattle package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# #
#, fuzzy #, fuzzy
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: squirrelbattle 3.14.1\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: squirrel-battle@crans.org\n"
"POT-Creation-Date: 2020-11-27 22:31+0100\n" "POT-Creation-Date: 2020-11-28 02:50+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"

View File

@ -1,14 +1,14 @@
# SOME DESCRIPTIVE TITLE. # SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # Copyright (C) YEAR ÿnérant, eichhornchen, nicomarg, charlse
# This file is distributed under the same license as the PACKAGE package. # This file is distributed under the same license as the squirrelbattle package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# #
#, fuzzy #, fuzzy
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: squirrelbattle 3.14.1\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: squirrel-battle@crans.org\n"
"POT-Creation-Date: 2020-11-27 22:31+0100\n" "POT-Creation-Date: 2020-11-28 02:50+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import gettext as gt import gettext as gt
import subprocess
from typing import Any, List from typing import Any, List
@ -36,6 +37,32 @@ class Translator:
def get_translator(cls) -> Any: def get_translator(cls) -> Any:
return cls.translators.get(cls.locale) 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: def gettext(message: str) -> str:
""" """