locales are working, added de_DE locale

This commit is contained in:
Jannes Höke
2016-05-21 21:41:38 +02:00
parent becc7e28dc
commit 5ece46527a
8 changed files with 540 additions and 170 deletions

View File

@ -26,7 +26,7 @@ from telegram import InlineQueryResultArticle, InputTextMessageContent, \
InlineQueryResultCachedSticker as Sticker
import card as c
from utils import *
from utils import display_color, display_name, list_subtract, _
def add_choose_color(results):
@ -35,7 +35,7 @@ def add_choose_color(results):
results.append(
InlineQueryResultArticle(
id=color,
title="Choose Color",
title=_("Choose Color"),
description=display_color(color),
input_message_content=
InputTextMessageContent(display_color(color))
@ -48,40 +48,34 @@ def add_other_cards(playable, player, results, game):
if not playable:
playable = list()
players = player_list(game)
results.append(
InlineQueryResultArticle(
"hand",
title="Cards (tap for game state):",
title=_("Cards (tap for game state):"),
description=', '.join([repr(card) for card in
list_subtract(player.cards, playable)]),
input_message_content=InputTextMessageContent(
"Current player: " + display_name(game.current_player.user) +
"\n" +
"Last card: " + repr(game.last_card) + "\n" +
"Players: " + " -> ".join(players))
input_message_content=game_info(game)
)
)
def player_list(game):
"""Generate list of player strings"""
return [player.user.first_name + " (%d cards)" % len(player.cards)
return ["{name} ({number} cards)"
.format(name=player.user.first_name, number=len(player.cards))
for player in game.players]
def add_no_game(results):
"""Add text result if user is not playing"""
results.append(
InlineQueryResultArticle(
"nogame",
title="You are not playing",
title=_("You are not playing"),
input_message_content=
InputTextMessageContent('Not playing right now. Use /new to start '
'a game or /join to join the current game '
'in this group')
InputTextMessageContent(_('Not playing right now. Use /new to '
'start a game or /join to join the '
'current game in this group'))
)
)
@ -91,38 +85,37 @@ def add_not_started(results):
results.append(
InlineQueryResultArticle(
"nogame",
title="The game wasn't started yet",
title=_("The game wasn't started yet"),
input_message_content=
InputTextMessageContent('Start the game with /start')
InputTextMessageContent(_('Start the game with /start'))
)
)
def add_draw(player, results):
"""Add option to draw"""
n = player.game.draw_counter or 1
results.append(
Sticker(
"draw", sticker_file_id=c.STICKERS['option_draw'],
input_message_content=
InputTextMessageContent('Drawing %d card(s)'
% (player.game.draw_counter or 1))
InputTextMessageContent(_('Drawing 1 card')
if n == 1 else
_('Drawing {number} cards')
.format(number=n))
)
)
def add_gameinfo(game, results):
"""Add option to show game info"""
players = player_list(game)
results.append(
Sticker(
"gameinfo",
sticker_file_id=c.STICKERS['option_info'],
input_message_content=InputTextMessageContent(
"Current player: " + display_name(game.current_player.user) +
"\n" +
"Last card: " + repr(game.last_card) + "\n" +
"Players: " + " -> ".join(players))
input_message_content=game_info(game)
)
)
@ -132,7 +125,7 @@ def add_pass(results):
results.append(
Sticker(
"pass", sticker_file_id=c.STICKERS['option_pass'],
input_message_content=InputTextMessageContent('Pass')
input_message_content=InputTextMessageContent(_('Pass'))
)
)
@ -144,14 +137,13 @@ def add_call_bluff(results):
"call_bluff",
sticker_file_id=c.STICKERS['option_bluff'],
input_message_content=
InputTextMessageContent("I'm calling your bluff!")
InputTextMessageContent(_("I'm calling your bluff!"))
)
)
def add_card(game, card, results, can_play):
"""Add an option that represents a card"""
players = player_list(game)
if can_play:
results.append(
@ -160,11 +152,18 @@ def add_card(game, card, results, can_play):
else:
results.append(
Sticker(str(uuid4()), sticker_file_id=c.STICKERS_GREY[str(card)],
input_message_content=InputTextMessageContent(
"Current player: " + display_name(
game.current_player.user) +
"\n" +
"Last card: " + repr(game.last_card) + "\n" +
"Players: " + " -> ".join(players)))
input_message_content=game_info(game))
)
def game_info(game):
players = player_list(game)
return InputTextMessageContent(
_("Current player: {name}")
.format(name=display_name(game.current_player.user)) +
"\n" +
_("Last card: {card}").format(card=repr(game.last_card)) +
"\n" +
_("Players: {player_list}")
.format(player_list=" -> ".join(players))
)