From c151e0f65620d4e0854b6b5bc7eb59b83fc7eb8e Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 27 Nov 2020 21:44:17 +0100 Subject: [PATCH] Menu items are translated --- locale/en/LC_MESSAGES/squirrelbattle.po | 20 ++++++++++---------- locale/fr/LC_MESSAGES/squirrelbattle.po | 20 ++++++++++---------- squirrelbattle/display/menudisplay.py | 2 +- squirrelbattle/menus.py | 14 +++++++------- squirrelbattle/tests/translations_test.py | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 squirrelbattle/tests/translations_test.py diff --git a/locale/en/LC_MESSAGES/squirrelbattle.po b/locale/en/LC_MESSAGES/squirrelbattle.po index 31fcdec..fb84fe2 100644 --- a/locale/en/LC_MESSAGES/squirrelbattle.po +++ b/locale/en/LC_MESSAGES/squirrelbattle.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-11-27 20:39+0100\n" +"POT-Creation-Date: 2020-11-27 21:43+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -35,27 +35,27 @@ msgstr "" msgid "{name} takes {amount} damage." msgstr "" -#: squirrelbattle/menus.py:45 +#: squirrelbattle/menus.py:45 squirrelbattle/tests/translations_test.py:14 msgid "New game" msgstr "" -#: squirrelbattle/menus.py:46 +#: squirrelbattle/menus.py:46 squirrelbattle/tests/translations_test.py:15 msgid "Resume" msgstr "" -#: squirrelbattle/menus.py:47 +#: squirrelbattle/menus.py:47 squirrelbattle/tests/translations_test.py:17 msgid "Save" msgstr "" -#: squirrelbattle/menus.py:48 +#: squirrelbattle/menus.py:48 squirrelbattle/tests/translations_test.py:16 msgid "Load" msgstr "" -#: squirrelbattle/menus.py:49 +#: squirrelbattle/menus.py:49 squirrelbattle/tests/translations_test.py:18 msgid "Settings" msgstr "" -#: squirrelbattle/menus.py:50 +#: squirrelbattle/menus.py:50 squirrelbattle/tests/translations_test.py:19 msgid "Exit" msgstr "" @@ -63,19 +63,19 @@ msgstr "" msgid "Back" msgstr "" -#: squirrelbattle/game.py:147 +#: squirrelbattle/game.py:147 squirrelbattle/game.py:148 msgid "" "Some keys are missing in your save file.\n" "Your save seems to be corrupt. It got deleted." msgstr "" -#: squirrelbattle/game.py:155 +#: squirrelbattle/game.py:155 squirrelbattle/game.py:156 msgid "" "No player was found on this map!\n" "Maybe you died?" msgstr "" -#: squirrelbattle/game.py:175 +#: squirrelbattle/game.py:175 squirrelbattle/game.py:176 msgid "" "The JSON file is not correct.\n" "Your save seems corrupted.It got deleted." diff --git a/locale/fr/LC_MESSAGES/squirrelbattle.po b/locale/fr/LC_MESSAGES/squirrelbattle.po index ab04ec8..0068f30 100644 --- a/locale/fr/LC_MESSAGES/squirrelbattle.po +++ b/locale/fr/LC_MESSAGES/squirrelbattle.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-11-27 20:39+0100\n" +"POT-Creation-Date: 2020-11-27 21:43+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -35,27 +35,27 @@ msgstr "{name} frappe {opponent}." msgid "{name} takes {amount} damage." msgstr "{name} prend {amount} points de dégât." -#: squirrelbattle/menus.py:45 +#: squirrelbattle/menus.py:45 squirrelbattle/tests/translations_test.py:14 msgid "New game" msgstr "Nouvelle partie" -#: squirrelbattle/menus.py:46 +#: squirrelbattle/menus.py:46 squirrelbattle/tests/translations_test.py:15 msgid "Resume" msgstr "Continuer" -#: squirrelbattle/menus.py:47 +#: squirrelbattle/menus.py:47 squirrelbattle/tests/translations_test.py:17 msgid "Save" msgstr "Sauvegarder" -#: squirrelbattle/menus.py:48 +#: squirrelbattle/menus.py:48 squirrelbattle/tests/translations_test.py:16 msgid "Load" msgstr "Charger" -#: squirrelbattle/menus.py:49 +#: squirrelbattle/menus.py:49 squirrelbattle/tests/translations_test.py:18 msgid "Settings" msgstr "Paramètres" -#: squirrelbattle/menus.py:50 +#: squirrelbattle/menus.py:50 squirrelbattle/tests/translations_test.py:19 msgid "Exit" msgstr "Quitter" @@ -63,7 +63,7 @@ msgstr "Quitter" msgid "Back" msgstr "Retour" -#: squirrelbattle/game.py:147 +#: squirrelbattle/game.py:147 squirrelbattle/game.py:148 msgid "" "Some keys are missing in your save file.\n" "Your save seems to be corrupt. It got deleted." @@ -71,7 +71,7 @@ msgstr "" "Certaines clés de votre ficher de sauvegarde sont manquantes.\n" "Votre sauvegarde semble corrompue. Elle a été supprimée." -#: squirrelbattle/game.py:155 +#: squirrelbattle/game.py:155 squirrelbattle/game.py:156 msgid "" "No player was found on this map!\n" "Maybe you died?" @@ -79,7 +79,7 @@ msgstr "" "Aucun joueur n'a été trouvé sur la carte !\n" "Peut-être êtes-vous mort ?" -#: squirrelbattle/game.py:175 +#: squirrelbattle/game.py:175 squirrelbattle/game.py:176 msgid "" "The JSON file is not correct.\n" "Your save seems corrupted.It got deleted." diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index 731ecee..e388a83 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -18,7 +18,7 @@ class MenuDisplay(Display): def update_menu(self, menu: Menu) -> None: self.menu = menu self.trueheight = len(self.values) - self.truewidth = max([len(a) for a in self.values]) + self.truewidth = max([len(str(a)) for a in self.values]) # Menu values are printed in pad self.pad = self.newpad(self.trueheight, self.truewidth + 2) diff --git a/squirrelbattle/menus.py b/squirrelbattle/menus.py index 56a7db2..3f6f7a0 100644 --- a/squirrelbattle/menus.py +++ b/squirrelbattle/menus.py @@ -42,15 +42,15 @@ class MainMenuValues(Enum): """ Values of the main menu """ - START = _("New game") - RESUME = _("Resume") - SAVE = _("Save") - LOAD = _("Load") - SETTINGS = _("Settings") - EXIT = _("Exit") + START = "New game" + RESUME = "Resume" + SAVE = "Save" + LOAD = "Load" + SETTINGS = "Settings" + EXIT = "Exit" def __str__(self): - return self.value + return _(self.value) class MainMenu(Menu): diff --git a/squirrelbattle/tests/translations_test.py b/squirrelbattle/tests/translations_test.py new file mode 100644 index 0000000..de93eb4 --- /dev/null +++ b/squirrelbattle/tests/translations_test.py @@ -0,0 +1,19 @@ +import unittest + +from squirrelbattle.translations import gettext as _, setlocale + + +class TestTranslations(unittest.TestCase): + def setUp(self) -> None: + setlocale("fr") + + def test_translations(self): + """ + Ensure that some strings are well-translated. + """ + self.assertEqual(_("New game"), "Nouvelle partie") + self.assertEqual(_("Resume"), "Continuer") + self.assertEqual(_("Load"), "Charger") + self.assertEqual(_("Save"), "Sauvegarder") + self.assertEqual(_("Settings"), "Paramètres") + self.assertEqual(_("Exit"), "Quitter")