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

205
bot.py
View file

@ -30,9 +30,6 @@ from telegram.ext import Updater, InlineQueryHandler, \
from telegram.ext.dispatcher import run_async
from telegram.utils.botan import Botan
from flufl.i18n import registry
from flufl.i18n import PackageStrategy
from game_manager import GameManager
from credentials import TOKEN, BOTAN_TOKEN
from start_bot import start_bot
@ -43,8 +40,9 @@ from utils import display_name
import card as c
from errors import (NoGameInChatError, LobbyClosedError, AlreadyJoinedError,
NotEnoughPlayersError, DeckEmptyError)
from database import db_session
import i18n
from database import db_session, user_locale
from utils import _
TIMEOUT = 2.5
@ -53,10 +51,6 @@ logging.basicConfig(
level=logging.DEBUG)
logger = logging.getLogger(__name__)
strategy = PackageStrategy('uno', i18n)
application = registry.register(strategy)
_ = application._
gm = GameManager()
u = Updater(token=TOKEN, workers=32)
dp = u.dispatcher
@ -91,7 +85,7 @@ help_text = ("Follow these steps:\n\n"
"<a href=\"https://telegram.me/storebot?start=mau_mau_bot\">"
"rate me</a>, join the "
"<a href=\"https://telegram.me/unobotupdates\">update channel</a>"
" and buy an UNO card game.\n")
" and buy an UNO card game.")
source_text = ("This bot is Free Software and licensed under the AGPL. "
"The code is available here: \n"
@ -127,6 +121,7 @@ def error(bot, update, error):
logger.exception(error)
@user_locale
def new_game(bot, update):
"""Handler for the /new command"""
chat_id = update.message.chat_id
@ -138,13 +133,14 @@ def new_game(bot, update):
game = gm.new_game(update.message.chat)
game.owner = update.message.from_user
send_async(bot, chat_id,
text="Created a new game! Join the game with /join "
"and start the game with /start")
text=_("Created a new game! Join the game with /join "
"and start the game with /start"))
if botan:
botan.track(update.message, 'New games')
@user_locale
def join_game(bot, update):
"""Handler for the /join command"""
chat = update.message.chat
@ -157,32 +153,33 @@ def join_game(bot, update):
gm.join_game(update.message.from_user, chat)
except LobbyClosedError:
send_async(bot, chat.id, text="The lobby is closed")
send_async(bot, chat.id, text=_("The lobby is closed"))
except NoGameInChatError:
send_async(bot, chat.id,
text="No game is running at the moment. "
"Create a new game with /new",
text=_("No game is running at the moment. "
"Create a new game with /new"),
reply_to_message_id=update.message.message_id)
except AlreadyJoinedError:
send_async(bot, chat.id,
text="You already joined the game. Start the game "
"with /start",
text=_("You already joined the game. Start the game "
"with /start"),
reply_to_message_id=update.message.message_id)
except DeckEmptyError:
send_async(bot, chat.id,
text="There are not enough cards left in the deck for new "
"players to join.",
text=_("There are not enough cards left in the deck for new "
"players to join."),
reply_to_message_id=update.message.message_id)
else:
send_async(bot, chat.id,
text="Joined the game",
text=_("Joined the game"),
reply_to_message_id=update.message.message_id)
@user_locale
def leave_game(bot, update):
"""Handler for the /leave command"""
chat = update.message.chat
@ -191,8 +188,8 @@ def leave_game(bot, update):
player = gm.player_for_user_in_chat(user, chat)
if player is None:
send_async(bot, chat.id, text="You are not playing in a game in "
"this group.",
send_async(bot, chat.id, text=_("You are not playing in a game in "
"this group."),
reply_to_message_id=update.message.message_id)
return
@ -203,18 +200,18 @@ def leave_game(bot, update):
gm.leave_game(user, chat)
except NoGameInChatError:
send_async(bot, chat.id, text="You are not playing in a game in "
"this group.",
send_async(bot, chat.id, text=_("You are not playing in a game in "
"this group."),
reply_to_message_id=update.message.message_id)
except NotEnoughPlayersError:
gm.end_game(chat, user)
send_async(bot, chat.id, text="Game ended!")
send_async(bot, chat.id, text=_("Game ended!"))
else:
send_async(bot, chat.id,
text="Okay. Next Player: " +
display_name(game.current_player.user),
text=_("Okay. Next Player: {name}").format(
name=display_name(game.current_player.user)),
reply_to_message_id=update.message.message_id)
@ -231,29 +228,30 @@ def select_game(bot, update):
break
else:
bot.sendMessage(update.callback_query.message.chat_id,
text="Game not found.",
text=_("Game not found."),
timeout=TIMEOUT)
return
back = [[InlineKeyboardButton(text='Back to last group',
back = [[InlineKeyboardButton(text=_("Back to last group"),
switch_inline_query='')]]
bot.answerCallbackQuery(update.callback_query.id,
text="Please switch to the group you selected!",
text=_("Please switch to the group you selected!"),
show_alert=False,
timeout=TIMEOUT)
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.message_id,
text="Selected group: %s\n"
text=_("Selected group: {group}\n"
"<b>Make sure that you switch to the correct "
"group!</b>"
% gm.userid_current[user_id].game.chat.title,
"group!</b>").format(
group=gm.userid_current[user_id].game.chat.title),
reply_markup=InlineKeyboardMarkup(back),
parse_mode=ParseMode.HTML,
timeout=TIMEOUT)
@user_locale
def status_update(bot, update):
"""Remove player from game if user leaves the group"""
chat = update.message.chat
@ -270,12 +268,13 @@ def status_update(bot, update):
pass
except NotEnoughPlayersError:
gm.end_game(chat, user)
send_async(bot, chat.id, text="Game ended!")
send_async(bot, chat.id, text=_("Game ended!"))
else:
send_async(bot, chat.id, text="Removing %s from the game"
% display_name(user))
send_async(bot, chat.id, text=_("Removing {name} from the game")
.format(name=display_name(user)))
@user_locale
def start_game(bot, update, args):
"""Handler for the /start command"""
@ -285,16 +284,18 @@ def start_game(bot, update, args):
try:
game = gm.chatid_games[chat.id][-1]
except (KeyError, IndexError):
send_async(bot, chat.id, text="There is no game running in this "
"chat. Create a new one with /new")
send_async(bot, chat.id,
text=_("There is no game running in this chat. Create "
"a new one with /new"))
return
if game.started:
send_async(bot, chat.id, text="The game has already started")
send_async(bot, chat.id, text=_("The game has already started"))
elif len(game.players) < 2:
send_async(bot, chat.id, text="At least two players must /join "
"the game before you can start it")
send_async(bot, chat.id,
text=_("At least two players must /join the game "
"before you can start it"))
else:
game.play_card(game.last_card)
@ -309,10 +310,12 @@ def start_game(bot, update, args):
timeout=TIMEOUT)
bot.sendMessage(chat.id,
text="First player: %s\n"
"Use /close to stop people from joining "
"the game."
% display_name(game.current_player.user),
text=_("First player: {name}\n"
"Use /close to stop people from "
"joining the game.")
.format(
name=display_name(game.current_player.user)
),
timeout=TIMEOUT)
send_first()
@ -333,13 +336,14 @@ def start_game(bot, update, args):
)
send_async(bot, update.message.chat_id,
text='Please select the group you want to play in.',
text=_('Please select the group you want to play in.'),
reply_markup=InlineKeyboardMarkup(groups))
else:
help(bot, update)
@user_locale
def close_game(bot, update):
"""Handler for the /close command"""
chat = update.message.chat
@ -347,25 +351,27 @@ def close_game(bot, update):
games = gm.chatid_games.get(chat.id)
if not games:
send_async(bot, chat.id, text="There is no running game in this chat.")
send_async(bot, chat.id,
text=_("There is no running game in this chat."))
return
game = games[-1]
if game.owner.id == user.id:
game.open = False
send_async(bot, chat.id, text="Closed the lobby. "
"No more players can join this game.")
send_async(bot, chat.id, text=_("Closed the lobby. "
"No more players can join this game."))
return
else:
send_async(bot, chat.id,
text="Only the game creator (%s) can do that"
% game.owner.first_name,
text=_("Only the game creator ({name}) can do that")
.format(name=game.owner.first_name),
reply_to_message_id=update.message.message_id)
return
@user_locale
def open_game(bot, update):
"""Handler for the /open command"""
chat = update.message.chat
@ -373,24 +379,26 @@ def open_game(bot, update):
games = gm.chatid_games.get(chat.id)
if not games:
send_async(bot, chat.id, text="There is no running game in this chat.")
send_async(bot, chat.id,
text=_("There is no running game in this chat."))
return
game = games[-1]
if game.owner.id == user.id:
game.open = True
send_async(bot, chat.id, text="Opened the lobby. "
"New players may /join the game.")
send_async(bot, chat.id, text=_("Opened the lobby. "
"New players may /join the game."))
return
else:
send_async(bot, chat.id,
text="Only the game creator (%s) can do that."
% game.owner.first_name,
text=_("Only the game creator ({name}) can do that")
.format(name=game.owner.first_name),
reply_to_message_id=update.message.message_id)
return
@user_locale
def skip_player(bot, update):
"""Handler for the /skip command"""
chat = update.message.chat
@ -398,8 +406,8 @@ def skip_player(bot, update):
player = gm.player_for_user_in_chat(user, chat)
if not player:
send_async(bot, chat.id, text="You are not playing in a game in this "
"chat.")
send_async(bot, chat.id,
text=_("You are not playing in a game in this chat."))
return
game = player.game
@ -412,8 +420,8 @@ def skip_player(bot, update):
if delta < skipped_player.waiting_time:
send_async(bot, chat.id,
text="Please wait %d seconds"
% (skipped_player.waiting_time - delta),
text=_("Please wait {time} seconds")
.format(time=(skipped_player.waiting_time - delta)),
reply_to_message_id=update.message.message_id)
elif skipped_player.waiting_time > 0:
@ -425,52 +433,56 @@ def skip_player(bot, update):
pass
send_async(bot, chat.id,
text="Waiting time to skip this player has "
"been reduced to %d seconds.\n"
"Next player: %s"
% (skipped_player.waiting_time,
display_name(next_player.user)))
text=_("Waiting time to skip this player has "
"been reduced to {time} seconds.\n"
"Next player: {name}")
.format(time=skipped_player.waiting_time,
name=display_name(next_player.user)))
game.turn()
else:
try:
gm.leave_game(skipped_player.user, chat)
send_async(bot, chat.id,
text="%s was skipped four times in a row "
text=_("{name1} was skipped four times in a row "
"and has been removed from the game.\n"
"Next player: %s"
% (display_name(skipped_player.user),
display_name(next_player.user)))
"Next player: {name2}")
.format(name1=display_name(skipped_player.user),
name2=display_name(next_player.user)))
except NotEnoughPlayersError:
send_async(bot, chat.id,
text="%s was skipped four times in a row "
text=_("{name} was skipped four times in a row "
"and has been removed from the game.\n"
"The game ended."
% display_name(skipped_player.user))
"The game ended.")
.format(name=display_name(skipped_player.user)))
gm.end_game(chat.id, skipped_player.user)
@user_locale
def help(bot, update):
"""Handler for the /help command"""
send_async(bot, update.message.chat_id, text=_(help_text),
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
@user_locale
def source(bot, update):
"""Handler for the /help command"""
send_async(bot, update.message.chat_id, text=source_text,
send_async(bot, update.message.chat_id, text=_(source_text),
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
@user_locale
def news(bot, update):
"""Handler for the /news command"""
send_async(bot, update.message.chat_id,
text="All news here: https://telegram.me/unobotupdates",
text=_("All news here: https://telegram.me/unobotupdates"),
disable_web_page_preview=True)
@user_locale
def reply_to_query(bot, update):
"""
Handler for inline queries.
@ -525,12 +537,13 @@ def reply_to_query(bot, update):
result.id += ':%d' % player.anti_cheat
if players and game and len(players) > 1:
switch = 'Current game: %s' % game.chat.title
switch = _('Current game: {game}').format(game=game.chat.title)
answer_async(bot, update.inline_query.id, results, cache_time=0,
switch_pm_text=switch, switch_pm_parameter='select')
@user_locale
def process_result(bot, update):
"""
Handler for chosen inline results.
@ -557,7 +570,8 @@ def process_result(bot, update):
return
elif int(anti_cheat) != last_anti_cheat:
send_async(bot, chat.id,
text="Cheat attempt by %s" % display_name(player.user))
text=_("Cheat attempt by {name}")
.format(name=display_name(player.user)))
return
elif result_id == 'call_bluff':
reset_waiting_time(bot, player)
@ -574,8 +588,9 @@ def process_result(bot, update):
do_play_card(bot, player, result_id)
if game in gm.chatid_games.get(chat.id, list()):
send_async(bot, chat.id, text="Next player: " +
display_name(game.current_player.user))
send_async(bot, chat.id,
text=_("Next player: {name}")
.format(name=display_name(game.current_player.user)))
def reset_waiting_time(bot, player):
@ -584,8 +599,9 @@ def reset_waiting_time(bot, player):
if player.waiting_time < 90:
player.waiting_time = 90
send_async(bot, chat.id, text="Waiting time for %s has been reset to "
"90 seconds" % display_name(player.user))
send_async(bot, chat.id,
text=_("Waiting time for {name} has been reset to 90 "
"seconds").format(name=display_name(player.user)))
def do_play_card(bot, player, result_id):
@ -597,17 +613,18 @@ def do_play_card(bot, player, result_id):
user = player.user
if game.choosing_color:
send_async(bot, chat.id, text="Please choose a color")
send_async(bot, chat.id, text=_("Please choose a color"))
if len(player.cards) == 1:
send_async(bot, chat.id, text="UNO!")
send_async(bot, chat.id, text=_("UNO!"))
if len(player.cards) == 0:
send_async(bot, chat.id, text="%s won!" % user.first_name)
send_async(bot, chat.id,
text=_("{name} won!").format(name=user.first_name))
try:
gm.leave_game(user, chat)
except NotEnoughPlayersError:
send_async(bot, chat.id, text="Game ended!")
send_async(bot, chat.id, text=_("Game ended!"))
gm.end_game(chat, user)
if botan:
@ -625,7 +642,7 @@ def do_draw(bot, player):
player.draw()
except DeckEmptyError:
send_async(bot, player.game.chat.id,
text="There are no more cards in the deck.")
text=_("There are no more cards in the deck."))
if (game.last_card.value == c.DRAW_TWO or
game.last_card.special == c.DRAW_FOUR) and \
@ -639,27 +656,27 @@ def do_call_bluff(bot, player):
chat = game.chat
if player.prev.bluffing:
send_async(bot, chat.id, text="Bluff called! Giving %d cards to %s"
% (game.draw_counter,
player.prev.user.first_name))
send_async(bot, chat.id,
text=_("Bluff called! Giving 4 cards to {name}")
.format(name=player.prev.user.first_name))
try:
player.prev.draw()
except DeckEmptyError:
send_async(bot, player.game.chat.id,
text="There are no more cards in the deck.")
text=_("There are no more cards in the deck."))
else:
game.draw_counter += 2
send_async(bot, chat.id, text="%s didn't bluff! Giving %d cards to %s"
% (player.prev.user.first_name,
game.draw_counter,
player.user.first_name))
send_async(bot, chat.id,
text="{name1} didn't bluff! Giving 6 cards to {name2}"
.format(name1=player.prev.user.first_name,
name2=player.user.first_name))
try:
player.draw()
except DeckEmptyError:
send_async(bot, player.game.chat.id,
text="There are no more cards in the deck.")
text=_("There are no more cards in the deck."))
game.turn()

View file

@ -18,7 +18,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from functools import wraps
from pony.orm import Database, db_session, Optional, Required, Set, PrimaryKey
from utils import _
# Database singleton
db = Database()
def user_locale(func):
@wraps(func)
def wrapped(*pargs, **kwargs):
_.push('de_DE') # TODO: Get user locale from Database
result = func(*pargs, **kwargs)
_.pop()
return result
return wrapped

View file

@ -1,2 +0,0 @@
bot.py
results.py

View file

@ -0,0 +1,352 @@
# Telegram bot to play UNO in group chats
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Jannes Höke <uno@jhoeke.de>, 2016.
#
#: bot.py:224
msgid ""
msgstr ""
"Project-Id-Version: mau_mau_bot 0.1\n"
"Report-Msgid-Bugs-To: uno@jhoeke.de\n"
"POT-Creation-Date: 2016-05-19 22:38+0200\n"
"PO-Revision-Date: 2016-05-21 21:16+0200\n"
"Last-Translator: Jannes Höke <uno@jhoeke.de>\n"
"Language-Team: Deutsch <uno@jhoeke.de>\n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Gtranslator 2.91.6\n"
#: bot.py:60
msgid ""
"Follow these steps:\n"
"\n"
"1. Add this bot to a group\n"
"2. In the group, start a new game with /new or join an already running game "
"with /join\n"
"3. After at least two players have joined, start the game with /start\n"
"4. Type <code>@mau_mau_bot</code> into your chat box and hit <b>space</b>, "
"or click the <code>via @mau_mau_bot</code> text next to messages. You will "
"see your cards (some greyed out), any extra options like drawing, and a <b>?"
"</b> to see the current game state. The <b>greyed out cards</b> are those "
"you <b>can not play</b> at the moment. Tap an option to execute the selected "
"action.\n"
"Players can join the game at any time. To leave a game, use /leave. If a "
"player takes more than 90 seconds to play, you can use /skip to skip that "
"player.\n"
"\n"
"Other commands (only game creator):\n"
"/close - Close lobby\n"
"/open - Open lobby\n"
"\n"
"<b>Experimental:</b> Play in multiple groups at the same time. Press the "
"<code>Current game: ...</code> button and select the group you want to play "
"a card in.\n"
"If you enjoy this bot, <a href=\"https://telegram.me/storebot?"
"start=mau_mau_bot\">rate me</a>, join the <a href=\"https://telegram.me/"
"unobotupdates\">update channel</a> and buy an UNO card game."
msgstr ""
"Folge den folgenden Schritten:\n"
"\n"
"1. Füge diesen Bot einer Gruppe hinzu\n"
"2. In einer Gruppe kannst du mit /new ein neues Spiel erstellen und mit /"
"join einem bestehenden Spiel beitreten\n"
"3. Nachdem mindestens zwei Spieler beigetreten sind, starte das Spiel mit /"
"start\n"
"3. Gib <code>@mau_mau_bot</code> in deine Chatbox ein und drücke die "
"<b>Leertaste</b>, oder tippe auf den <code>via @mau_mau_bot</code>-Text "
"neben oder über den Nachrichten. Du siehst deine Karten (einige in grau), "
"zusätzliche Optionen wie z. B. Ziehen, und ein <b>?</b> um den Infos über "
"das laufende Spiel anzuzeigen. Die <b>grauen Karten</b> kannst du gerade "
"<b>nicht spielen</b>. Tippe eine der Optionen oder Karten an, um diese "
"Aktion auszuführen bzw. die Karte zu spielen. \n"
"Spieler können dem Spiel jederzeit beitreten. Um das Spiel zu verlassen, "
"benutze /leave. Wenn ein Spieler länger als 90 Sekunden braucht, kannst du "
"ihn mit /skip überspringen.\n"
"\n"
"Weitere Kommandos (nur Spiel-Ersteller):\n"
"/close - Lobby schließen\n"
"/open - Lobby öffnen\n"
"\n"
"<b>Experimentell</b>: Spiele in mehreren Gruppen gleichzeitig. Um die "
"Gruppe, in der du deine Karte spielen willst, auszuwählen, tippe auf den "
"<code>Aktuelles Spiel: ...</code>-Button.\n"
"Wenn dir dieser Bot gefällt, <a href=\"https://telegram.me/storebot?"
"start=mau_mau_bot\">bewerte ihn</a>, tritt dem <a href=\"https://telegram.me/"
"unobotupdates\">News-Channel</a> bei und kaufe ein UNO Kartenspiel."
#: bot.py:88
msgid ""
"This bot is Free Software and licensed under the AGPL. The code is available "
"here: \n"
"https://github.com/jh0ker/mau_mau_bot"
msgstr ""
"Dieser Bot ist Freie Software und lizenziert unter der AGPL. Der Quellcode "
"ist hier verfügbar:\n"
"https://github.com/jh0ker/mau_mau_bot"
#: bot.py:133
msgid ""
"Created a new game! Join the game with /join and start the game with /start"
msgstr ""
"Neues Spiel erstellt! Tritt dem Spiel mit /join bei und starte es mit /start"
#: bot.py:152
msgid "The lobby is closed"
msgstr "Die Lobby ist geschlossen"
#: bot.py:156
msgid "No game is running at the moment. Create a new game with /new"
msgstr "Zur Zeit läuft kein Spiel. Erstelle ein neues mit /new"
#: bot.py:162
msgid "You already joined the game. Start the game with /start"
msgstr "Du bist dem Spiel bereits beigetreten. Starte es mit /start"
#: bot.py:167
msgid "Joined the game"
msgstr "Spiel beigetreten"
#: bot.py:179 bot.py:191
msgid "You are not playing in a game in this group."
msgstr "Du spielst in keinem Spiel in dieser Gruppe."
#: bot.py:197 bot.py:258 bot.py:595
msgid "Game ended!"
msgstr "Spiel beendet!"
#: bot.py:201
msgid "Okay. Next Player: {name}"
msgstr "Okay. Nächster Spieler: {name}"
#: bot.py:219
msgid "Game not found."
msgstr "Spiel nicht gefunden."
#: bot.py:223
msgid "Back to last group"
msgstr "Zurück zur letzten Gruppe"
#: bot.py:227
msgid "Please switch to the group you selected!"
msgstr "Bitte wechsele zu der Gruppe, die du gewählt hast!"
#: bot.py:233
#, python-format
msgid ""
"Selected group: {group}\n"
"<b>Make sure that you switch to the correct group!</b>"
msgstr ""
"Ausgewählte Gruppe: {group}\n"
"<b>Stell sicher, dass du in die richtige Gruppe wechselst!</b>"
#: bot.py:260
#, python-format
msgid "Removing {name} from the game"
msgstr "Entferne {name} aus dem Spiel"
#: bot.py:273
msgid "There is no game running in this chat. Create a new one with /new"
msgstr ""
"In dieser Gruppe gibt es kein laufendes Spiel. Erstelle ein neues mit /new"
#: bot.py:278
msgid "The game has already started"
msgstr "Das Spiel hat bereits begonnen"
#: bot.py:281
msgid "At least two players must /join the game before you can start it"
msgstr ""
"Es müssen mindestens zwei Spieler dem Spiel beitreten, bevor du es starten "
"kannst"
#: bot.py:297
#, python-format
msgid ""
"First player: {name}\n"
"Use /close to stop people from joining the game."
msgstr ""
"Erster Spieler: {name}\n"
"Benutze /close, um zu verhindern, dass weitere Spieler beitreten."
#: bot.py:321
msgid "Please select the group you want to play in."
msgstr "Bitte wähle die Gruppe, in der du spielen willst."
#: bot.py:335 bot.py:361
msgid "There is no running game in this chat."
msgstr "In dieser Gruppe läuft gerade kein Spiel."
#: bot.py:342
msgid "Closed the lobby. No more players can join this game."
msgstr ""
"Lobby geschlossen. Diesem Spiel können keine weiteren Spieler beitreten."
#: bot.py:348 bot.py:373
#, python-format
msgid "Only the game creator ({name}) can do that."
msgstr "Dies kann nur der Ersteller des Spiels ({name}) tun."
#: bot.py:368
msgid "Opened the lobby. New players may /join the game."
msgstr "Lobby geöffnet. Neue Spieler können nun beitreten."
#: bot.py:386
msgid "You are not playing in a game in this chat."
msgstr "Du spielst kein Spiel in dieser Gruppe."
#: bot.py:400
#, python-format
msgid "Please wait {time} seconds"
msgstr "Bitte warte {time} Sekunden"
#: bot.py:413
#, python-format
msgid ""
"Waiting time to skip this player has been reduced to {time} seconds.\n"
"Next player: {name}"
msgstr ""
"Die Wartezeit um diesen Spieler zu überspringen wurde auf {time} Sekunden "
"reduziert.\n"
"Nächster Spieler: {name}"
#: bot.py:424
#, python-format
msgid ""
"{name1} was skipped four times in a row and has been removed from the game.\n"
"Next player: {name2}"
msgstr ""
"{name1} wurde vier Mal hintereinander übersprungen und daher aus dem Spiel "
"entfernt.\n"
"Nächster Spieler: {name2}"
#: bot.py:432
#, python-format
msgid ""
"{name} was skipped four times in a row and has been removed from the game.\n"
"The game ended."
msgstr ""
"{name1} wurde vier Mal hintereinander übersprungen und daher aus dem Spiel "
"entfernt.\n"
"Das Spiel wurde beendet."
#: bot.py:455
msgid "All news here: https://telegram.me/unobotupdates"
msgstr "Alle News hier: https://telegram.me/unobotupdates"
#: bot.py:513
#, python-format
msgid "Current game: %s"
msgstr "Aktuelles Spiel: {game}"
#: bot.py:545
#, python-format
msgid "Cheat attempt by %s"
msgstr "{name} hat versucht zu schummeln!"
#: bot.py:562
msgid "Next player: "
msgstr "Nächster Spieler: {name}"
#: bot.py:572
#, python-format
msgid "Waiting time for {name} has been reset to 90 seconds"
msgstr "Die Wartezeit für {name} wurde auf 90 Sekunden zurückgesetzt."
#: bot.py:585
msgid "Please choose a color"
msgstr "Bitte wähle eine Farbe"
#: bot.py:591
#, python-format
msgid "{name} won!"
msgstr "{name} hat gewonnen!"
#: bot.py:613 bot.py:635 bot.py:647
msgid "There are no more cards in the deck."
msgstr "Es sind keine Karten mehr im Deck."
#: bot.py:627
#, python-format
msgid "Bluff called! Giving 4 cards to {name}"
msgstr "Bluff gecalled! {name} bekommt 4 Karten."
#: bot.py:639
#, python-format
msgid "{name1} didn't bluff! Giving 6 cards to {name2}"
msgstr "{name1} hat nicht geblufft! {name2} bekommt 6 Karten."
#: results.py:38
msgid "Choose Color"
msgstr "Wähle Farbe"
#: results.py:56
msgid "Cards (tap for game state):"
msgstr "Karten (tippe für Spielinfo):"
#: results.py:60 results.py:123 results.py:165
msgid "Current player: {name}"
msgstr "Aktueller Spieler: {name}"
#: results.py:61 results.py:124 results.py:167
msgid "Last card: {card}"
msgstr "Letzte Karte: {card}"
#: results.py:62 results.py:125 results.py:168
msgid "Players: {player_list}"
msgstr "Spieler: {player_list}"
#: results.py:72
#, python-format
msgid "{name} ({number} cards)"
msgstr "{name} ({number} Karten)"
#: results.py:81
msgid "You are not playing"
msgstr "Du spielst gerade nicht"
#: results.py:83
msgid ""
"Not playing right now. Use /new to start a game or /join to join the current "
"game in this group"
msgstr ""
"Du spielst gerade nicht. Benutze /new um ein neues Spiel zu starten oder /"
"join, um einem bestehenden Spiel beizutreten."
#: results.py:95
msgid "The game wasn't started yet"
msgstr "Das Spiel wurde noch nicht gestartet."
#: results.py:97
msgid "Start the game with /start"
msgstr "Starte das Spiel mit /start"
#: results.py:108
#, python-format
msgid "Drawing 1 card"
msgstr "Zieht 1 Karte"
msgid "Drawing {number} cards"
msgstr "Zieht {number} Karten"
#: results.py:136
msgid "Pass"
msgstr "Passe"
#: results.py:148
msgid "I'm calling your bluff!"
msgstr "Ich glaube du bluffst!"

View file

@ -25,10 +25,10 @@ msgstr ""
"PO-Revision-Date: 2016-05-19 22:38+0200\n"
"Last-Translator: Jannes Höke <uno@jhoeke.de>\n"
"Language-Team: en <uno@jhoeke.de>\n"
"Language: en\n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Content-Transfer-Encoding: utf-8\n"
#: bot.py:60
@ -57,7 +57,7 @@ msgid "Follow these steps:\n"
"a card in.\n"
"If you enjoy this bot, <a href=\"https://telegram.me/storebot?"
"start=mau_mau_bot\">rate me</a>, join the <a href=\"https://telegram.me/"
"unobotupdates\">update channel</a> and buy an UNO card game.\n"
"unobotupdates\">update channel</a> and buy an UNO card game."
msgstr ""
#: bot.py:88
@ -95,7 +95,7 @@ msgid "Game ended!"
msgstr ""
#: bot.py:201
msgid "Okay. Next Player: "
msgid "Okay. Next Player: {name}"
msgstr ""
#: bot.py:219
@ -196,20 +196,16 @@ msgstr ""
#: bot.py:513
#, python-format
msgid "Current game: %s"
msgstr ""
#: bot.py:533
msgid "Selected result: "
msgid "Current game: {group}"
msgstr ""
#: bot.py:545
#, python-format
msgid "Cheat attempt by %s"
msgid "Cheat attempt by {name}"
msgstr ""
#: bot.py:562
msgid "Next player: "
msgid "Next player: {name}"
msgstr ""
#: bot.py:572
@ -217,39 +213,27 @@ msgstr ""
msgid "Waiting time for {name} has been reset to 90 seconds"
msgstr ""
#: bot.py:577
msgid "Plays the selected card and sends an update to the group if needed"
msgstr ""
#: bot.py:585
msgid "Please choose a color"
msgstr ""
#: bot.py:588
msgid "UNO!"
msgstr ""
#: bot.py:591
#, python-format
msgid "{name} won!"
msgstr ""
#: bot.py:601
msgid "Played cards"
msgstr ""
#: bot.py:613 bot.py:635 bot.py:647
msgid "There are no more cards in the deck."
msgstr ""
#: bot.py:627
#, python-format
msgid "Bluff called! Giving {number} cards to {name}"
msgid "Bluff called! Giving 4 cards to {name}"
msgstr ""
#: bot.py:639
#, python-format
msgid "{name1} didn't bluff! Giving {number} cards to {name2}"
msgid "{name1} didn't bluff! Giving 6 cards to {name2}"
msgstr ""
#: results.py:38
@ -261,23 +245,20 @@ msgid "Cards (tap for game state):"
msgstr ""
#: results.py:60 results.py:123 results.py:165
msgid "Current player: "
msgid "Current player: {name}"
msgstr ""
#: results.py:61 results.py:124 results.py:167
msgid "\n"
"Last card: "
msgid "Last card: {card}"
msgstr ""
#: results.py:62 results.py:125 results.py:168
msgid "\n"
"Players: "
msgid "Players: {player_list}"
msgstr ""
#: results.py:72
#, python-format
msgid " ({number} cards)"
msgid "{name} ({number} cards)"
msgstr ""
#: results.py:81
@ -299,10 +280,11 @@ msgstr ""
#: results.py:108
#, python-format
msgid "Drawing one card"
msgid_plural "Drawing {number} cards"
msgstr[0] ""
msgstr[1] ""
msgid "Drawing 1 card"
msgstr ""
msgid "Drawing {number} cards"
msgstr ""
#: results.py:136
msgid "Pass"

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))
)

View file

@ -18,7 +18,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from flufl.i18n import registry
from flufl.i18n import PackageStrategy
from telegram import Emoji
import locales
strategy = PackageStrategy('unobot', locales)
application = registry.register(strategy)
_ = application._
def list_subtract(list1, list2):