Translate entities

This commit is contained in:
Yohann D'ANELLO
2020-11-27 22:33:58 +01:00
parent 8f85093eb8
commit 70ae60b9a4
5 changed files with 113 additions and 14 deletions

View File

@ -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: