Translate strings

This commit is contained in:
Yohann D'ANELLO
2020-11-27 20:42:19 +01:00
parent e3be4b4f3f
commit 2498fd2a61
8 changed files with 163 additions and 29 deletions

View File

@ -3,10 +3,10 @@
import curses
from ..entities.player import Player
from ..translations import gettext as _
from .display import Display
from squirrelbattle.entities.player import Player
class StatsDisplay(Display):
player: Player
@ -31,12 +31,12 @@ class StatsDisplay(Display):
self.player.dexterity, self.player.constitution)
self.addstr(self.pad, 3, 0, string3)
inventory_str = "Inventaire : " + "".join(
inventory_str = _("Inventory:") + " " + "".join(
self.pack[item.name.upper()] for item in self.player.inventory)
self.addstr(self.pad, 8, 0, inventory_str)
if self.player.dead:
self.addstr(self.pad, 10, 0, "VOUS ÊTES MORT",
self.addstr(self.pad, 10, 0, _("YOU ARE DEAD"),
curses.A_BOLD | curses.A_BLINK | curses.A_STANDOUT
| self.color_pair(3))

View File

@ -1,5 +1,6 @@
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
# SPDX-License-Identifier: GPL-3.0-or-later
from json import JSONDecodeError
from random import randint
from typing import Any, Optional
@ -13,6 +14,7 @@ from .interfaces import Map, Logs
from .resources import ResourceManager
from .settings import Settings
from . import menus
from .translations import gettext as _
from typing import Callable
@ -142,16 +144,16 @@ class Game:
try:
self.map.load_state(d)
except KeyError:
self.message = "Some keys are missing in your save file.\n" \
"Your save seems to be corrupt. It got deleted."
self.message = _("Some keys are missing in your save file.\n"
"Your save seems to be corrupt. It got deleted.")
os.unlink(ResourceManager.get_config_path("save.json"))
self.display_actions(DisplayActions.UPDATE)
return
players = self.map.find_entities(Player)
if not players:
self.message = "No player was found on this map!\n" \
"Maybe you died?"
self.message = _("No player was found on this map!\n"
"Maybe you died?")
self.player.health = 0
self.display_actions(DisplayActions.UPDATE)
return
@ -170,8 +172,9 @@ class Game:
state = json.loads(f.read())
self.load_state(state)
except JSONDecodeError:
self.message = "The JSON file is not correct.\n" \
"Your save seems corrupted. It got deleted."
self.message = _("The JSON file is not correct.\n"
"Your save seems corrupted."
"It got deleted.")
os.unlink(file_path)
self.display_actions(DisplayActions.UPDATE)

View File

@ -6,7 +6,8 @@ from math import sqrt
from random import choice, randint
from typing import List, Optional
from squirrelbattle.display.texturepack import TexturePack
from .display.texturepack import TexturePack
from .translations import gettext as _
class Logs:
@ -390,7 +391,8 @@ class FightingEntity(Entity):
"""
Deals damage to the opponent, based on the stats
"""
return f"{self.name} hits {opponent.name}. "\
return _("{name} hits {opponent}.")\
.format(name=str(self), opponent=str(opponent)) + " "\
+ opponent.take_damage(self, self.strength)
def take_damage(self, attacker: "Entity", amount: int) -> str:
@ -400,8 +402,10 @@ class FightingEntity(Entity):
self.health -= amount
if self.health <= 0:
self.die()
return f"{self.name} takes {amount} damage."\
+ (f" {self.name} dies." if self.health <= 0 else "")
return _("{name} takes {amount} damage.")\
.format(name=str(self), amount=str(amount)) \
+ (" " + "{name} dies.".format(name=str(self))
if self.health <= 0 else "")
def die(self) -> None:
"""

View File

@ -7,6 +7,7 @@ from typing import Any, Optional
from .display.texturepack import TexturePack
from .enums import GameMode, KeyValues, DisplayActions
from .settings import Settings
from .translations import gettext as _
class Menu:
@ -41,12 +42,12 @@ class MainMenuValues(Enum):
"""
Values of the main menu
"""
START = 'Nouvelle partie'
RESUME = 'Continuer'
SAVE = 'Sauvegarder'
LOAD = 'Charger'
SETTINGS = 'Paramètres'
EXIT = 'Quitter'
START = _("New game")
RESUME = _("Resume")
SAVE = _("Save")
LOAD = _("Load")
SETTINGS = _("Settings")
EXIT = _("Exit")
def __str__(self):
return self.value
@ -67,7 +68,7 @@ class SettingsMenu(Menu):
def update_values(self, settings: Settings) -> None:
self.values = list(settings.__dict__.items())
self.values.append(("RETURN", ["", "Retour"]))
self.values.append(("RETURN", ["", _("Back")]))
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str,
game: Any) -> None: