CLI to manage messages
This commit is contained in:
parent
8aad15f07b
commit
7c0cf3e029
18
main.py
18
main.py
|
@ -2,8 +2,24 @@
|
||||||
|
|
||||||
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
from squirrelbattle.bootstrap import Bootstrap
|
from squirrelbattle.bootstrap import Bootstrap
|
||||||
|
from squirrelbattle.translations import Translator
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
Bootstrap.run_game()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
parser.add_argument("--makemessages", "-mm", action="store_true",
|
||||||
|
help="Extract translatable strings")
|
||||||
|
parser.add_argument("--compilemessages", "-cm", action="store_true",
|
||||||
|
help="Compile translatable strings")
|
||||||
|
|
||||||
|
args = parser.parse_args(sys.argv[1:])
|
||||||
|
if args.makemessages:
|
||||||
|
Translator.makemessages()
|
||||||
|
elif args.compilemessages:
|
||||||
|
Translator.compilemessages()
|
||||||
|
else:
|
||||||
|
Bootstrap.run_game()
|
||||||
|
|
|
@ -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 os
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
@ -18,11 +19,14 @@ class Translator:
|
||||||
translators: dict = {}
|
translators: dict = {}
|
||||||
|
|
||||||
for language in SUPPORTED_LOCALES:
|
for language in SUPPORTED_LOCALES:
|
||||||
translators[language] = gt.translation(
|
dir = Path(__file__).parent / "locale" / language / "LC_MESSAGES"
|
||||||
"squirrelbattle",
|
dir.mkdir(parents=True) if not dir.is_dir() else None
|
||||||
localedir=Path(__file__).parent / "locale",
|
if os.path.isfile(dir / "squirrelbattle.mo"):
|
||||||
languages=[language],
|
translators[language] = gt.translation(
|
||||||
)
|
"squirrelbattle",
|
||||||
|
localedir=Path(__file__).parent / "locale",
|
||||||
|
languages=[language],
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setlocale(cls, lang: str) -> None:
|
def setlocale(cls, lang: str) -> None:
|
||||||
|
@ -41,19 +45,21 @@ class Translator:
|
||||||
@classmethod
|
@classmethod
|
||||||
def makemessages(cls) -> None: # pragma: no cover
|
def makemessages(cls) -> None: # pragma: no cover
|
||||||
for language in cls.SUPPORTED_LOCALES:
|
for language in cls.SUPPORTED_LOCALES:
|
||||||
|
file_name = Path(__file__).parent / "locale" / language \
|
||||||
|
/ "LC_MESSAGES" / "squirrelbattle.po"
|
||||||
args = ["find", "squirrelbattle", "-iname", "*.py"]
|
args = ["find", "squirrelbattle", "-iname", "*.py"]
|
||||||
find = subprocess.Popen(args, cwd=Path(__file__).parent.parent,
|
find = subprocess.Popen(args, cwd=Path(__file__).parent.parent,
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
args = ["xargs", "xgettext", "--from-code", "utf-8",
|
args = ["xargs", "xgettext", "--from-code", "utf-8",
|
||||||
"--join-existing",
|
|
||||||
"--add-comments",
|
"--add-comments",
|
||||||
"--package-name=squirrelbattle",
|
"--package-name=squirrelbattle",
|
||||||
"--package-version=3.14.1",
|
"--package-version=3.14.1",
|
||||||
"--copyright-holder=ÿnérant, eichhornchen, "
|
"--copyright-holder=ÿnérant, eichhornchen, "
|
||||||
"nicomarg, charlse",
|
"nicomarg, charlse",
|
||||||
"--msgid-bugs-address=squirrel-battle@crans.org",
|
"--msgid-bugs-address=squirrel-battle@crans.org",
|
||||||
"-o", Path(__file__).parent / "locale" / language
|
"-o", file_name]
|
||||||
/ "LC_MESSAGES" / "squirrelbattle.po"]
|
if file_name.is_file():
|
||||||
|
args.append("--join-existing")
|
||||||
print(f"Make {language} messages...")
|
print(f"Make {language} messages...")
|
||||||
subprocess.Popen(args, stdin=find.stdout)
|
subprocess.Popen(args, stdin=find.stdout)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue