From 70ae60b9a428c129355361aa6f71175155bd16bc Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 27 Nov 2020 22:33:58 +0100 Subject: [PATCH] Translate entities --- locale/en/LC_MESSAGES/squirrelbattle.po | 47 ++++++++++++++++++++-- locale/fr/LC_MESSAGES/squirrelbattle.mo | Bin 2310 -> 2607 bytes locale/fr/LC_MESSAGES/squirrelbattle.po | 47 ++++++++++++++++++++-- squirrelbattle/interfaces.py | 14 +++++-- squirrelbattle/tests/translations_test.py | 19 ++++++++- 5 files changed, 113 insertions(+), 14 deletions(-) diff --git a/locale/en/LC_MESSAGES/squirrelbattle.po b/locale/en/LC_MESSAGES/squirrelbattle.po index a027782..d77e823 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 22:20+0100\n" +"POT-Creation-Date: 2020-11-27 22:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -25,12 +25,12 @@ msgstr "" msgid "YOU ARE DEAD" msgstr "" -#: squirrelbattle/interfaces.py:394 +#: squirrelbattle/interfaces.py:394 squirrelbattle/interfaces.py:398 #, python-brace-format msgid "{name} hits {opponent}." msgstr "" -#: squirrelbattle/interfaces.py:405 +#: squirrelbattle/interfaces.py:405 squirrelbattle/interfaces.py:410 #, python-brace-format msgid "{name} takes {amount} damage." msgstr "" @@ -83,50 +83,89 @@ msgid "" msgstr "" #: squirrelbattle/settings.py:21 squirrelbattle/tests/translations_test.py:21 +#: squirrelbattle/tests/translations_test.py:25 msgid "Main key to move up" msgstr "" #: squirrelbattle/settings.py:22 squirrelbattle/tests/translations_test.py:23 +#: squirrelbattle/tests/translations_test.py:27 msgid "Secondary key to move up" msgstr "" #: squirrelbattle/settings.py:23 squirrelbattle/tests/translations_test.py:25 +#: squirrelbattle/tests/translations_test.py:29 msgid "Main key to move down" msgstr "" #: squirrelbattle/settings.py:24 squirrelbattle/tests/translations_test.py:27 +#: squirrelbattle/tests/translations_test.py:31 msgid "Secondary key to move down" msgstr "" #: squirrelbattle/settings.py:25 squirrelbattle/tests/translations_test.py:29 +#: squirrelbattle/tests/translations_test.py:33 msgid "Main key to move left" msgstr "" #: squirrelbattle/settings.py:26 squirrelbattle/tests/translations_test.py:31 +#: squirrelbattle/tests/translations_test.py:35 msgid "Secondary key to move left" msgstr "" #: squirrelbattle/settings.py:27 squirrelbattle/tests/translations_test.py:33 +#: squirrelbattle/tests/translations_test.py:37 msgid "Main key to move right" msgstr "" #: squirrelbattle/settings.py:29 squirrelbattle/tests/translations_test.py:35 +#: squirrelbattle/tests/translations_test.py:39 msgid "Secondary key to move right" msgstr "" #: squirrelbattle/settings.py:30 squirrelbattle/tests/translations_test.py:37 +#: squirrelbattle/tests/translations_test.py:41 msgid "Key to validate a menu" msgstr "" #: squirrelbattle/settings.py:31 squirrelbattle/tests/translations_test.py:39 +#: squirrelbattle/tests/translations_test.py:43 msgid "Texture pack" msgstr "" #: squirrelbattle/settings.py:32 squirrelbattle/tests/translations_test.py:40 +#: squirrelbattle/tests/translations_test.py:44 msgid "Language" msgstr "" -#: squirrelbattle/interfaces.py:407 +#: squirrelbattle/interfaces.py:407 squirrelbattle/interfaces.py:412 #, python-brace-format msgid "{name} dies." msgstr "" + +#: squirrelbattle/tests/translations_test.py:47 +msgid "player" +msgstr "" + +#: squirrelbattle/tests/translations_test.py:49 +msgid "tiger" +msgstr "" + +#: squirrelbattle/tests/translations_test.py:50 +msgid "hedgehog" +msgstr "" + +#: squirrelbattle/tests/translations_test.py:51 +msgid "rabbit" +msgstr "" + +#: squirrelbattle/tests/translations_test.py:52 +msgid "teddy bear" +msgstr "" + +#: squirrelbattle/tests/translations_test.py:54 +msgid "bomb" +msgstr "" + +#: squirrelbattle/tests/translations_test.py:55 +msgid "heart" +msgstr "" diff --git a/locale/fr/LC_MESSAGES/squirrelbattle.mo b/locale/fr/LC_MESSAGES/squirrelbattle.mo index bc9146e56582ef46663f44ca84d8b24c1f344325..12e6fe990a48a5dcee90cc5a5049f39393074960 100644 GIT binary patch delta 938 zcmXxiKWGzS7{~D^?U~l9Rnz#VYBdcM8Z1%lBnkylP{Bng9p%oP$w`xomqe%{w>b#n za5~vt0)k){XSIVU=-?m@oeB;*h?5Tf`TpYF!@ck4-rSq#{d>3YtQc<;oJU5KDTgR? zIkRJUdWeeni4Ois{exq)hlkDf;y8}t460uh_uzc$1ysK)IDt1&{qNy%v)B?|^8D}` zmEbKNzz?Zk@gVIyANOM!mEaUE;aS{{t9Ty!Y5NEA*k7tG=uqi@W2o^a2F47=i&iv^ zJT^zAgePzxF5na{sm<>6Pzml+jo?EZOaL{}KJwT)mA=2jS^S7c@po#4j}^wZMP7Dd zj2H0%ZpF{I4L4BTpkh+? zGX3xd$zku)_9xsydjlu&8_r^$ZDT_QlPx0i8w|{e4R%gfNIRRwVP1Aqv`e}pWu1Q( zO03YpS?C^U#yWS!^na{?C5l$9&;`>G=)84QigAi2tzmTC6U+omsm)^d*-o zB`2M!1utxR*6`h^OI@q`jj(R*Wp~AoEOI?B=vvpW)mBO#U920_`TcgwZTfdgwZQLG z*A|_Yb4f{jySkqAB5S8gf5hy{pwnU;5x|Bgi6ir$UVvCayZW7ccHMIoM(h&59 zmWZIezn~gw)Fr5?rSG}k3+H|Aeeb?^-Z}R!(g@c-!p^xcrim!gCgzDp9~Z{DU&O(@ zwSc{>cW@l{u?LUs^9GKwKDAz=i3yRqw3u{rBihwTG>7^#F>4BESnuH^ z)=)pt#4WtUe*D2z^zpa4&f)|Xa26}Nrl>R2eAfYyAo=B%iN4^WCVEEQ@MboMd|`}r z3l}iLLv;n?SjHi|z#QIS2*0rp|4`o#20QO1th*Q|znn19jrUl?CmhBl$~?pzY61_Z z@C9S|j`ozOq*E=$nf8MjG}nAfJ4%C0VdeoBJ;uDAi4Oe%9hyLsg$ZppIb?*;iu4>K zgmy~@4KZVo>wuk$_v>%_qS>l@a8z}RrE;lSDlW?Q+NPV_$hhfDGVLt~Do(Q\n" "Language-Team: LANGUAGE \n" @@ -25,12 +25,12 @@ msgstr "Inventaire :" msgid "YOU ARE DEAD" msgstr "VOUS ÊTES MORT" -#: squirrelbattle/interfaces.py:394 +#: squirrelbattle/interfaces.py:394 squirrelbattle/interfaces.py:398 #, python-brace-format msgid "{name} hits {opponent}." msgstr "{name} frappe {opponent}." -#: squirrelbattle/interfaces.py:405 +#: squirrelbattle/interfaces.py:405 squirrelbattle/interfaces.py:410 #, python-brace-format msgid "{name} takes {amount} damage." msgstr "{name} prend {amount} points de dégât." @@ -89,50 +89,89 @@ msgstr "" "Votre sauvegarde semble corrompue. Elle a été supprimée." #: squirrelbattle/settings.py:21 squirrelbattle/tests/translations_test.py:21 +#: squirrelbattle/tests/translations_test.py:25 msgid "Main key to move up" msgstr "Touche principale pour aller vers le haut" #: squirrelbattle/settings.py:22 squirrelbattle/tests/translations_test.py:23 +#: squirrelbattle/tests/translations_test.py:27 msgid "Secondary key to move up" msgstr "Touche secondaire pour aller vers le haut" #: squirrelbattle/settings.py:23 squirrelbattle/tests/translations_test.py:25 +#: squirrelbattle/tests/translations_test.py:29 msgid "Main key to move down" msgstr "Touche principale pour aller vers le bas" #: squirrelbattle/settings.py:24 squirrelbattle/tests/translations_test.py:27 +#: squirrelbattle/tests/translations_test.py:31 msgid "Secondary key to move down" msgstr "Touche secondaire pour aller vers le bas" #: squirrelbattle/settings.py:25 squirrelbattle/tests/translations_test.py:29 +#: squirrelbattle/tests/translations_test.py:33 msgid "Main key to move left" msgstr "Touche principale pour aller vers la gauche" #: squirrelbattle/settings.py:26 squirrelbattle/tests/translations_test.py:31 +#: squirrelbattle/tests/translations_test.py:35 msgid "Secondary key to move left" msgstr "Touche secondaire pour aller vers la gauche" #: squirrelbattle/settings.py:27 squirrelbattle/tests/translations_test.py:33 +#: squirrelbattle/tests/translations_test.py:37 msgid "Main key to move right" msgstr "Touche principale pour aller vers la droite" #: squirrelbattle/settings.py:29 squirrelbattle/tests/translations_test.py:35 +#: squirrelbattle/tests/translations_test.py:39 msgid "Secondary key to move right" msgstr "Touche secondaire pour aller vers la droite" #: squirrelbattle/settings.py:30 squirrelbattle/tests/translations_test.py:37 +#: squirrelbattle/tests/translations_test.py:41 msgid "Key to validate a menu" msgstr "Touche pour valider un menu" #: squirrelbattle/settings.py:31 squirrelbattle/tests/translations_test.py:39 +#: squirrelbattle/tests/translations_test.py:43 msgid "Texture pack" msgstr "Pack de textures" #: squirrelbattle/settings.py:32 squirrelbattle/tests/translations_test.py:40 +#: squirrelbattle/tests/translations_test.py:44 msgid "Language" msgstr "Langue" -#: squirrelbattle/interfaces.py:407 +#: squirrelbattle/interfaces.py:407 squirrelbattle/interfaces.py:412 #, python-brace-format msgid "{name} dies." msgstr "{name} meurt." + +#: squirrelbattle/tests/translations_test.py:47 +msgid "player" +msgstr "joueur" + +#: squirrelbattle/tests/translations_test.py:49 +msgid "tiger" +msgstr "tigre" + +#: squirrelbattle/tests/translations_test.py:50 +msgid "hedgehog" +msgstr "hérisson" + +#: squirrelbattle/tests/translations_test.py:51 +msgid "rabbit" +msgstr "lapin" + +#: squirrelbattle/tests/translations_test.py:52 +msgid "teddy bear" +msgstr "nounours" + +#: squirrelbattle/tests/translations_test.py:54 +msgid "bomb" +msgstr "bombe" + +#: squirrelbattle/tests/translations_test.py:55 +msgid "heart" +msgstr "cœur" diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 78c1a15..90e5d69 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -315,6 +315,10 @@ class Entity: from squirrelbattle.entities.items import Item return isinstance(self, Item) + @property + def translated_name(self) -> str: + return _(self.name.replace("_", " ")) + @staticmethod def get_all_entity_classes(): """ @@ -392,8 +396,9 @@ class FightingEntity(Entity): Deals damage to the opponent, based on the stats """ return _("{name} hits {opponent}.")\ - .format(name=self.name, opponent=opponent.name) + " "\ - + opponent.take_damage(self, self.strength) + .format(name=_(self.translated_name.capitalize()), + opponent=_(opponent.translated_name)) + " " + \ + opponent.take_damage(self, self.strength) def take_damage(self, attacker: "Entity", amount: int) -> str: """ @@ -403,8 +408,9 @@ class FightingEntity(Entity): if self.health <= 0: self.die() return _("{name} takes {amount} damage.")\ - .format(name=self.name, amount=str(amount)) \ - + (" " + _("{name} dies.").format(name=self.name) + .format(name=self.translated_name.capitalize(), amount=str(amount))\ + + (" " + _("{name} dies.") + .format(name=self.translated_name.capitalize()) if self.health <= 0 else "") def die(self) -> None: diff --git a/squirrelbattle/tests/translations_test.py b/squirrelbattle/tests/translations_test.py index 0d190d6..1931224 100644 --- a/squirrelbattle/tests/translations_test.py +++ b/squirrelbattle/tests/translations_test.py @@ -7,9 +7,9 @@ class TestTranslations(unittest.TestCase): def setUp(self) -> None: setlocale("fr") - def test_translations(self) -> None: + def test_main_menu_translation(self) -> None: """ - Ensure that some strings are well-translated. + Ensure that the main menu is translated. """ self.assertEqual(_("New game"), "Nouvelle partie") self.assertEqual(_("Resume"), "Continuer") @@ -18,6 +18,10 @@ class TestTranslations(unittest.TestCase): self.assertEqual(_("Settings"), "Paramètres") self.assertEqual(_("Exit"), "Quitter") + def test_settings_menu_translation(self) -> None: + """ + Ensure that the settings menu is translated. + """ self.assertEqual(_("Main key to move up"), "Touche principale pour aller vers le haut") self.assertEqual(_("Secondary key to move up"), @@ -38,3 +42,14 @@ class TestTranslations(unittest.TestCase): "Touche pour valider un menu") self.assertEqual(_("Texture pack"), "Pack de textures") self.assertEqual(_("Language"), "Langue") + + def test_entities_translation(self) -> None: + self.assertEqual(_("player"), "joueur") + + self.assertEqual(_("tiger"), "tigre") + self.assertEqual(_("hedgehog"), "hérisson") + self.assertEqual(_("rabbit"), "lapin") + self.assertEqual(_("teddy bear"), "nounours") + + self.assertEqual(_("bomb"), "bombe") + self.assertEqual(_("heart"), "cœur")