From ffc8b904417fdb23def673a097ade06fea0003d8 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 28 Nov 2020 02:54:04 +0100 Subject: [PATCH] Create functions that call xgettext or msgfmt --- locale/en/LC_MESSAGES/squirrelbattle.po | 10 ++++----- locale/fr/LC_MESSAGES/squirrelbattle.po | 10 ++++----- squirrelbattle/translations.py | 27 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/locale/en/LC_MESSAGES/squirrelbattle.po b/locale/en/LC_MESSAGES/squirrelbattle.po index d77e823..21e45e6 100644 --- a/locale/en/LC_MESSAGES/squirrelbattle.po +++ b/locale/en/LC_MESSAGES/squirrelbattle.po @@ -1,14 +1,14 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. +# Copyright (C) YEAR ÿnérant, eichhornchen, nicomarg, charlse +# This file is distributed under the same license as the squirrelbattle package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-11-27 22:31+0100\n" +"Project-Id-Version: squirrelbattle 3.14.1\n" +"Report-Msgid-Bugs-To: squirrel-battle@crans.org\n" +"POT-Creation-Date: 2020-11-28 02:50+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/locale/fr/LC_MESSAGES/squirrelbattle.po b/locale/fr/LC_MESSAGES/squirrelbattle.po index fa4e1b0..b14ef50 100644 --- a/locale/fr/LC_MESSAGES/squirrelbattle.po +++ b/locale/fr/LC_MESSAGES/squirrelbattle.po @@ -1,14 +1,14 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. +# Copyright (C) YEAR ÿnérant, eichhornchen, nicomarg, charlse +# This file is distributed under the same license as the squirrelbattle package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-11-27 22:31+0100\n" +"Project-Id-Version: squirrelbattle 3.14.1\n" +"Report-Msgid-Bugs-To: squirrel-battle@crans.org\n" +"POT-Creation-Date: 2020-11-28 02:50+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/squirrelbattle/translations.py b/squirrelbattle/translations.py index 47ec9fb..1cee88b 100644 --- a/squirrelbattle/translations.py +++ b/squirrelbattle/translations.py @@ -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: """