diff --git a/magicked_admin/chatbot/__init__.py b/magicked_admin/chatbot/__init__.py index d82a0f71..2d349b41 100644 --- a/magicked_admin/chatbot/__init__.py +++ b/magicked_admin/chatbot/__init__.py @@ -1,4 +1,8 @@ -INIT_TEMPLATE = ''' +import gettext + +_ = gettext.gettext + +INIT_TEMPLATE = _(''' ; The contents of this file will be ran in sequence on the server it is named ; after when the program starts. Lines starting with ; will be ignored. There ; is no need to prefix commands with ! in this file. @@ -7,4 +11,4 @@ ; silent ; start_wc -w 1 Welcome to wave 1 ; silent -''' +''') diff --git a/magicked_admin/chatbot/chatbot.py b/magicked_admin/chatbot/chatbot.py index a95d665a..62ef4cad 100644 --- a/magicked_admin/chatbot/chatbot.py +++ b/magicked_admin/chatbot/chatbot.py @@ -1,4 +1,5 @@ from os import path +import gettext from chatbot import INIT_TEMPLATE from chatbot.command_map import CommandMap @@ -8,6 +9,8 @@ from web_admin.constants import * from utils import warning +_ = gettext.gettext + class Chatbot(ChatListener): @@ -16,7 +19,7 @@ def __init__(self, server, name=None): if name: self.name = name else: - self.name = "Unnamed" + self.name = _("Unnamed") self.chat = server.web_admin.chat self.chat.add_listener(self) @@ -54,7 +57,7 @@ def command_handler(self, username, args, user_flags): self.chat.submit_message(response) def execute_script(self, filename): - debug("Executing script: " + path.basename(filename)) + debug(_("Executing script: ") + path.basename(filename)) with open(filename) as script: for line in script: diff --git a/magicked_admin/chatbot/command_map.py b/magicked_admin/chatbot/command_map.py index 2a1e387c..e2b04f28 100644 --- a/magicked_admin/chatbot/command_map.py +++ b/magicked_admin/chatbot/command_map.py @@ -1,8 +1,12 @@ +import gettext + from chatbot.commands.event_commands import * from chatbot.commands.info_commands import * from chatbot.commands.player_commands import * from chatbot.commands.server_commands import * +_ = gettext.gettext + # Internal command definitions COMMAND_NEW_WAVE = "new_wave" # Params: wave number COMMAND_NEW_GAME = "new_game" @@ -22,51 +26,51 @@ def generate_map(self): command_map = { # Operator commands - 'start_jc': CommandStartJoinCommand(self.server, scheduler), - 'stop_jc': CommandStopJoinCommands(self.server, scheduler), - 'start_wc': CommandStartWaveCommand(self.server, scheduler), - 'stop_wc': CommandStopWaveCommands(self.server, scheduler), - 'start_tc': CommandStartTimeCommand(self.server, scheduler), - 'stop_tc': CommandStopTimeCommands(self.server, scheduler), - 'start_trc': CommandStartTraderCommand(self.server, scheduler), - 'stop_trc': CommandStopTraderCommands(self.server, scheduler), - 'enforce_dosh': CommandEnforceDosh(self.server), - 'say': CommandSay(self.server), - 'restart': CommandRestart(self.server), - 'load_map': CommandLoadMap(self.server), - 'password': CommandPassword(self.server), - 'silent': CommandSilent(self.server, self.chatbot), - 'run': CommandRun(self.server, self.chatbot), - 'length': CommandLength(self.server), - 'difficulty': CommandDifficulty(self.server), - 'game_mode': CommandGameMode(self.server), - 'players': CommandPlayers(self.server), - 'kick': CommandKick(self.server), - 'ban': CommandBan(self.server), - 'op': CommandOp(self.server), - 'deop': CommandDeop(self.server), - 'marquee': CommandMarquee(self.server, self.chatbot), + _('start_jc'): CommandStartJoinCommand(self.server, scheduler), + _('stop_jc'): CommandStopJoinCommands(self.server, scheduler), + _('start_wc'): CommandStartWaveCommand(self.server, scheduler), + _('stop_wc'): CommandStopWaveCommands(self.server, scheduler), + _('start_tc'): CommandStartTimeCommand(self.server, scheduler), + _('stop_tc'): CommandStopTimeCommands(self.server, scheduler), + _('start_trc'): CommandStartTraderCommand(self.server, scheduler), + _('stop_trc'): CommandStopTraderCommands(self.server, scheduler), + _('enforce_dosh'): CommandEnforceDosh(self.server), + _('say'): CommandSay(self.server), + _('restart'): CommandRestart(self.server), + _('load_map'): CommandLoadMap(self.server), + _('password'): CommandPassword(self.server), + _('silent'): CommandSilent(self.server, self.chatbot), + _('run'): CommandRun(self.server, self.chatbot), + _('length'): CommandLength(self.server), + _('difficulty'): CommandDifficulty(self.server), + _('game_mode'): CommandGameMode(self.server), + _('players'): CommandPlayers(self.server), + _('kick'): CommandKick(self.server), + _('ban'): CommandBan(self.server), + _('op'): CommandOp(self.server), + _('deop'): CommandDeop(self.server), + _('marquee'): CommandMarquee(self.server, self.chatbot), # Player commands - 'commands': CommandCommands(self.server), - 'record_wave': CommandHighWave(self.server), - 'game': CommandGame(self.server), - 'kills': CommandKills(self.server), - 'dosh': CommandDosh(self.server), - 'top_kills': CommandTopKills(self.server), - 'top_dosh': CommandTopDosh(self.server), - 'top_time': CommandTopTime(self.server), - 'top_wave_kills': CommandTopWaveKills(self.server), - 'top_wave_dosh': CommandTopWaveDosh(self.server), - 'stats': CommandStats(self.server), - 'game_time': CommandGameTime(self.server), - 'server_kills': CommandServerKills(self.server), - 'server_dosh': CommandServerDosh(self.server), - 'map': CommandGameMap(self.server), - 'maps': CommandGameMaps(self.server), - 'player_count': CommandPlayerCount(self.server), - 'scoreboard': CommandScoreboard(self.server), - 'sb': CommandScoreboard(self.server) + _('commands'): CommandCommands(self.server), + _('record_wave'): CommandHighWave(self.server), + _('game'): CommandGame(self.server), + _('kills'): CommandKills(self.server), + _('dosh'): CommandDosh(self.server), + _('top_kills'): CommandTopKills(self.server), + _('top_dosh'): CommandTopDosh(self.server), + _('top_time'): CommandTopTime(self.server), + _('top_wave_kills'): CommandTopWaveKills(self.server), + _('top_wave_dosh'): CommandTopWaveDosh(self.server), + _('stats'): CommandStats(self.server), + _('game_time'): CommandGameTime(self.server), + _('server_kills'): CommandServerKills(self.server), + _('server_dosh'): CommandServerDosh(self.server), + _('map'): CommandGameMap(self.server), + _('maps'): CommandGameMaps(self.server), + _('player_count'): CommandPlayerCount(self.server), + _('scoreboard'): CommandScoreboard(self.server), + _('sb'): CommandScoreboard(self.server) } return command_map diff --git a/magicked_admin/chatbot/command_scheduler.py b/magicked_admin/chatbot/command_scheduler.py index f583865d..4e556c43 100644 --- a/magicked_admin/chatbot/command_scheduler.py +++ b/magicked_admin/chatbot/command_scheduler.py @@ -1,11 +1,13 @@ import threading import time +import gettext from chatbot.commands.command import Command from utils import warning from web_admin.chat import ChatListener from web_admin.constants import * +_ = gettext.gettext ALL_WAVES = 999 @@ -50,11 +52,10 @@ def unschedule_commands(self, command_type): stopped += 1 if stopped: - message = "Stopped {} command".format(stopped) - message += "s" if stopped > 1 else "" + message = _("Stopped {} command(s)").format(stopped) return message else: - return "None running" + return _("None running") def receive_message(self, username, message, user_flags): """ @@ -102,8 +103,8 @@ def __init__(self, server, command, run_once=False, poll=False): def execute(self, username, args, user_flags): warning( - "Scheduled command ({}) ran directly by {}, please use " - "CommandScheduler".format( + _("Scheduled command ({}) ran directly by {}, please use " + "CommandScheduler").format( " ".join(args), username ) diff --git a/magicked_admin/chatbot/commands/command.py b/magicked_admin/chatbot/commands/command.py index f3a05a69..966b529e 100644 --- a/magicked_admin/chatbot/commands/command.py +++ b/magicked_admin/chatbot/commands/command.py @@ -1,10 +1,13 @@ from argparse import ArgumentError +import gettext from chatbot.commands.argument_parser import ArgumentParser from utils import debug, BANNER_URL from utils.text import pad_output from web_admin.constants import * +_ = gettext.gettext + class Command: def __init__(self, server, admin_only=True, requires_patch=False): @@ -12,20 +15,19 @@ def __init__(self, server, admin_only=True, requires_patch=False): self.admin_only = admin_only self.requires_patch = requires_patch - not_auth_message = "You're not authorised to use that command" + not_auth_message = _("You're not authorised to use that command") self.not_auth_message = pad_output(not_auth_message) - not_supported_message = "This action isn't supported without Killing" \ - " Floor 2 Magicked Administrator's server" \ - " side patch! Please review the " \ - "documentation at '{}' for guidance."\ - .format(BANNER_URL) + not_supported_message = _( + "This action isn't supported without Killing Floor 2 Magicked " + "Administrator's server side patch! Please review the " + "documentation at '{}' for guidance." + ).format(BANNER_URL) self.not_supported_message = pad_output(not_supported_message) - self.help_text = "The help text for this command hasn't been written!" - self.currency_symbol = "$" - # TODO: implement - self.language = "en_GB.lang" + self.help_text = _("The help text for this command hasn't been " + "written!") + self.currency_symbol = _("$") self.parser = ArgumentParser(add_help=False) self.parser.add_argument( @@ -51,7 +53,7 @@ def authorise(self, username, user_flags): authorised = (not self.admin_only) or op or internal or admin if not authorised: - debug("Auth failure, username: {}, user flags: {:b}".format( + debug(_("Auth failure, username: {}, user flags: {:b}").format( username, user_flags )) diff --git a/magicked_admin/database/database.py b/magicked_admin/database/database.py index 4b08918e..159a1b1b 100644 --- a/magicked_admin/database/database.py +++ b/magicked_admin/database/database.py @@ -1,9 +1,11 @@ import sqlite3 from os import path from threading import Lock +import gettext from utils import find_data_file, info +_ = gettext.gettext lock = Lock() @@ -24,7 +26,7 @@ def __init__(self, name): self.cur = self.conn.cursor() def build_schema(self): - info("Building new database...") + info(_("Building new database...")) conn = sqlite3.connect(self.sqlite_db_file) cur = conn.cursor() diff --git a/magicked_admin/magicked_admin.py b/magicked_admin/magicked_admin.py index 09d4ccf3..960d293b 100644 --- a/magicked_admin/magicked_admin.py +++ b/magicked_admin/magicked_admin.py @@ -18,14 +18,17 @@ from utils import banner, die, find_data_file, info, warning from utils.net import phone_home from utils.text import str_to_bool +import gettext + +_ = gettext.gettext init() parser = argparse.ArgumentParser( - description='Killing Floor 2 Magicked Administrator' + description=_('Killing Floor 2 Magicked Administrator') ) parser.add_argument('-s', '--skip_setup', action='store_true', - help='Skips the guided setup process') + help=_('Skips the guided setup process')) args = parser.parse_args() banner() @@ -87,7 +90,7 @@ def run(self): Chatbot(server, settings.setting(server_name, "username")) - info("Initialisation complete!\n") + info(_("Initialisation complete!\n")) while True: command = input() @@ -97,7 +100,7 @@ def run(self): def terminate(self, signal, frame): if self.sigint_count > 1: print() # \n - warning("Closing immediately!") + warning(_("Closing immediately!")) os._exit(0) return @@ -106,7 +109,7 @@ def terminate(self, signal, frame): return print() # \n - info("Program interrupted, saving data...") + info(_("Program interrupted, saving data...")) for server in self.servers: server.close() diff --git a/magicked_admin/server/game.py b/magicked_admin/server/game.py index 78439252..7c9839d6 100644 --- a/magicked_admin/server/game.py +++ b/magicked_admin/server/game.py @@ -1,5 +1,8 @@ import web_admin as api from web_admin.constants import * +import gettext + +_ = gettext.gettext class Game: @@ -23,7 +26,7 @@ def __init__(self, game_map, game_type): self.password_enabled = False def __str__(self): - return "Mode: {}\nMap: {}\nDifficulty: {}\nWave {}/{}".format( + return _("Mode: {}\nMap: {}\nDifficulty: {}\nWave {}/{}").format( GAME_TYPE_DISPLAY[self.game_type], self.game_map.name, DIFF_DISPLAY[self.difficulty], @@ -63,7 +66,11 @@ def reset_stats(self): self.votes = 0 def __str__(self): - return ("Title: {}\nPlays survival: {}\nPlays survival_vs: {}\n" - "Plays endless: {}\nPlays weekly: {}") \ - .format(self.title, self.plays_survival, self.plays_survival_vs, - self.plays_endless, self.plays_weekly) + map_str = _("Title: {}\nPlays survival: {}\nPlays survival_vs: {}\n" + "Plays endless: {}\nPlays weekly: {}").format( + self.title, self.plays_survival, + self.plays_survival_vs, self.plays_endless, + self.plays_weekly + ) + + return map_str diff --git a/magicked_admin/server/game_tracker.py b/magicked_admin/server/game_tracker.py index 33adfb6e..bf7ad1de 100644 --- a/magicked_admin/server/game_tracker.py +++ b/magicked_admin/server/game_tracker.py @@ -1,12 +1,14 @@ import threading import time - +import gettext from colorama import init from termcolor import colored from utils import BANNER_URL, warning from web_admin.constants import * + +_ = gettext.gettext init() @@ -51,9 +53,9 @@ def __is_new_game(game_now, game_before): if game_now.wave is None: # Initial mode change if game_before.game_type != game_now.game_type: - message = ("Game type ({}) support not installed, please " - "patch your webadmin to correct this! Guidance is " - "available at: {}") + message = (_("Game type ({}) support not installed, please " + "patch your webadmin to correct this! Guidance is" + " available at: {}")) warning(message.format( game_now.game_type, colored(BANNER_URL, 'magenta') )) diff --git a/magicked_admin/server/motd_updater.py b/magicked_admin/server/motd_updater.py index 13640fd3..8e57b4a3 100644 --- a/magicked_admin/server/motd_updater.py +++ b/magicked_admin/server/motd_updater.py @@ -1,10 +1,13 @@ import threading import time +import gettext from os import path from utils import debug, find_data_file, warning from utils.text import millify, trim_string +_ = gettext.gettext() + class MotdUpdater(threading.Thread): @@ -17,7 +20,7 @@ def __init__(self, server, scoreboard_type): if not path.exists(find_data_file(self.motd_path)): warning( - "No MOTD file for {} found, pulling from web admin!".format( + _("No MOTD file for {} found, pulling from web admin!").format( self.server.name ) ) @@ -39,7 +42,7 @@ def run(self): motd = self.render_motd(self.motd) self.server.web_admin.set_motd(motd) - debug("Updated the MOTD!") + debug(_("Updated the MOTD!")) time.sleep(self.time_interval) @@ -56,8 +59,8 @@ def render_motd(self, src_motd): scores = self.server.database.top_dosh() else: warning( - "Scoreboard_type not recognised '{}' for {}. Options are: " - "dosh, kills".format( + _("Scoreboard_type not recognised '{}' for {}. Options are: " + "dosh, kills").format( self.scoreboard_type, self.server.name ) ) diff --git a/magicked_admin/server/player.py b/magicked_admin/server/player.py index 038eb397..ff4593f9 100644 --- a/magicked_admin/server/player.py +++ b/magicked_admin/server/player.py @@ -1,4 +1,7 @@ import time +import gettext + +_ = gettext.gettext class Player: @@ -32,7 +35,7 @@ def __init__(self, username, perk): self.network_id = None self.player_key = None self.ip = None - self.country = "Unknown" + self.country = _("Unknown") self.country_code = "??" self.op = False @@ -50,6 +53,6 @@ def reset_stats(self): self.sessions = 0 def __str__(self): - return "Username: {}\nCountry: {} ({})\nOP: {}\nSteam ID:{}".format( + return _("Username: {}\nCountry: {} ({})\nOP: {}\nSteam ID:{}").format( self.username, self.country, self.ip, self.op, self.steam_id ) diff --git a/magicked_admin/server/server.py b/magicked_admin/server/server.py index e5354a1d..aa82a075 100644 --- a/magicked_admin/server/server.py +++ b/magicked_admin/server/server.py @@ -1,4 +1,5 @@ from termcolor import colored +import gettext import web_admin as api from database.database import ServerDatabase @@ -8,14 +9,16 @@ from utils import debug, info, warning from web_admin.constants import * +_ = gettext.gettext + class Server: def __init__(self, name, address, username, password): self.name = name - info("Connecting to {} ({})...".format(name, address)) + info(_("Connecting to {} ({})...").format(name, address)) self.web_admin = api.WebAdmin(address, username, password, name) - info("Connected to {} ({})".format(name, address)) + info(_("Connected to {} ({})").format(name, address)) self.database = ServerDatabase(name) @@ -84,12 +87,12 @@ def toggle_game_password(self): self.web_admin.toggle_game_password() def write_all_players(self): - debug("Flushing players on {}".format(self.name)) + debug(_("Flushing players on {}").format(self.name)) for player in self.players: self.database.save_player(player) def write_game_map(self): - debug("Writing game to database ({})".format( + debug(_("Writing game to database ({})").format( self.game.game_map.name )) self.database.save_game_map(self.game.game_map) @@ -188,7 +191,7 @@ def event_player_join(self, player): new_player.sessions += 1 self.players.append(new_player) - message = "Player {} joined {} from {}" \ + message = _("Player {} joined {} from {}") \ .format(new_player.username, self.name, new_player.country) print(colored(message, 'cyan')) self.web_admin.chat.handle_message( @@ -201,7 +204,7 @@ def event_player_quit(self, player): self.players.remove(player) self.database.save_player(player) - message = "Player {} left {}" \ + message = _("Player {} left {}") \ .format(player.username, self.name) print(colored(message, 'cyan')) self.web_admin.chat.handle_message("internal_command", @@ -210,11 +213,11 @@ def event_player_quit(self, player): def event_player_death(self, player): player.total_deaths += 1 - message = "Player {} died on {}".format(player.username, self.name) + message = _("Player {} died on {}").format(player.username, self.name) print(colored(message, 'red')) def event_new_game(self): - message = "New game on {}, map: {}, mode: {}" \ + message = _("New game on {}, map: {}, mode: {}") \ .format(self.name, self.game.game_map.name, GAME_TYPE_DISPLAY[self.game.game_type]) print(colored(message, 'magenta')) @@ -231,14 +234,14 @@ def event_new_game(self): elif self.game.game_type == GAME_TYPE_WEEKLY: self.game.game_map.plays_weekly += 1 else: - warning("Unknown game_type {}".format(self.game.game_type)) + warning(_("Unknown game_type {}").format(self.game.game_type)) self.game.game_map.plays_other += 1 self.web_admin.chat.handle_message("internal_command", "!new_game", USER_TYPE_INTERNAL) def event_end_game(self, victory=False): - debug("End game on {}, map: {}, mode: {}, victory: {}".format( + debug(_("End game on {}, map: {}, mode: {}, victory: {}").format( self.name, self.game.game_map.title, self.game.game_type, str(victory) )) diff --git a/magicked_admin/settings.py b/magicked_admin/settings.py index db601827..f8a5bc8e 100644 --- a/magicked_admin/settings.py +++ b/magicked_admin/settings.py @@ -1,10 +1,13 @@ import configparser import os from getpass import getpass +import gettext from utils import die, fatal, find_data_file, info from utils.net import resolve_address +_ = gettext.gettext() + CONFIG_PATH = find_data_file("conf/magicked_admin.conf") CONFIG_PATH_DISPLAY = "conf/magicked_admin.conf" @@ -24,14 +27,15 @@ 'scoreboard_type', 'dosh_threshold', 'max_players'] -CONFIG_DIE_MESG = "Please correct this manually or delete '{}' to create " \ - "a clean config next run.".format(CONFIG_PATH) +CONFIG_DIE_MESG = _("Please correct this manually or delete '{}' to create " + "a clean config next run.").format(CONFIG_PATH) class Settings: def __init__(self, skip_setup=False): if not os.path.exists(CONFIG_PATH): - info("No configuration was found, first time setup is required!") + info(_("No configuration was found, first time setup is " + "required!")) if not skip_setup: config = self.construct_config_interactive() @@ -42,24 +46,24 @@ def __init__(self, skip_setup=False): config.write(config_file) if skip_setup: - info("Guided setup was skipped, a template has been " - "generated.") - die("Setup is not complete yet, please amend '{}' with your " - "server details.".format(CONFIG_PATH_DISPLAY)) + info(_("Guided setup was skipped, a template has been " + "generated.")) + die(_("Setup is not complete yet, please amend '{}' with your " + "server details.").format(CONFIG_PATH_DISPLAY)) try: self.config = configparser.ConfigParser() self.config.read(CONFIG_PATH) except configparser.DuplicateOptionError as e: - fatal("Configuration error(s) found!\nSection '{}' has a duplicate" - " setting: '{}'.".format(e.section, e.option)) + fatal(_("Configuration error(s) found!\nSection '{}' has a " + "duplicate setting: '{}'.").format(e.section, e.option)) die(CONFIG_DIE_MESG, pause=True) config_errors = self.validate_config(self.config) if config_errors: - fatal("Configuration error(s) found!") + fatal(_("Configuration error(s) found!")) for error in config_errors: print("\t\t" + error) die(CONFIG_DIE_MESG, pause=True) @@ -75,7 +79,7 @@ def sections(self): @staticmethod def construct_config_interactive(): - print(" Please input your web admin details below.") + print(_(" Please input your web admin details below.")) new_config = configparser.ConfigParser() new_config.add_section(SETTINGS_DEFAULT['server_name']) @@ -87,17 +91,18 @@ def construct_config_interactive(): while True: address = input( - "\nAddress [default - localhost:8080]: ") or "localhost:8080" + _("\nAddress [default - localhost:8080]: ") + ) or "localhost:8080" resolved_address = resolve_address(address) if resolved_address: break else: - print("Address not responding!\nAccepted formats are: " - "'ip:port', 'domain', or 'domain:port'") + print(_("Address not responding!\nAccepted formats are: " + "'ip:port', 'domain', or 'domain:port'")) - username = input("Username [default - Admin]: ") or "Admin" + username = input(_("Username [default - Admin]: ")) or "Admin" password = getpass( - "Password (will not echo) [default - 123]: ") or "123" + _("Password (will not echo) [default - 123]: ")) or "123" print() # \n new_config.set(SETTINGS_DEFAULT['server_name'], 'address', @@ -133,7 +138,7 @@ def validate_config(config): errors = [] if len(sections) < 1: - errors.append("Config file has no sections.") + errors.append(_("Config file has no sections.")) return errors for section in sections: @@ -142,8 +147,8 @@ def validate_config(config): config.get(section, setting) except configparser.NoOptionError: errors.append( - "Section '{}' is missing a required setting: " - "'{}'.".format(section, setting) + _("Section '{}' is missing a required setting: " + "'{}'.").format(section, setting) ) return errors diff --git a/magicked_admin/utils/__init__.py b/magicked_admin/utils/__init__.py index b9e0883c..b5ea22fc 100644 --- a/magicked_admin/utils/__init__.py +++ b/magicked_admin/utils/__init__.py @@ -1,9 +1,10 @@ import os import sys - +import gettext from colorama import init from termcolor import colored +_ = gettext.gettext init() # __debug__ is always true when building w/ cx_freeze, no known solution @@ -18,7 +19,7 @@ def die(message=None, pause=False): if message: print(colored(' [!] ', 'red') + message) if pause: - input("\nPress enter to exit...") + input(_("\nPress enter to exit...")) sys.exit(0) diff --git a/magicked_admin/utils/net.py b/magicked_admin/utils/net.py index 635dde87..893fe80d 100644 --- a/magicked_admin/utils/net.py +++ b/magicked_admin/utils/net.py @@ -1,8 +1,10 @@ from urllib.parse import urlparse from urllib.request import urlopen - +import gettext import requests +_ = gettext.gettext + # Add http scheme if no scheme def __add_address_scheme(address): @@ -53,7 +55,7 @@ def phone_home(): # Get geographical information for an ip address def get_country(ip): url = "http://ip-api.com/" + "/json/" + ip - unknown = ("Unknown", "??") + unknown = (_("Unknown"), "??") geo_data = requests.get(url).json() diff --git a/magicked_admin/web_admin/web_admin.py b/magicked_admin/web_admin/web_admin.py index 447be60f..54696d3a 100644 --- a/magicked_admin/web_admin/web_admin.py +++ b/magicked_admin/web_admin/web_admin.py @@ -1,5 +1,5 @@ from itertools import groupby - +import gettext from lxml import html from utils import warning @@ -9,6 +9,8 @@ from web_admin.constants import * from web_admin.web_interface import WebInterface +_ = gettext.gettext + class WebAdmin(object): def __init__(self, address, username, password, server_name="unnamed"): @@ -87,7 +89,7 @@ def has_game_password(self): def toggle_game_password(self): if not self.__game_password: - warning("Tried to toggle game password before setting value") + warning(_("Tried to toggle game password before setting value")) return False if self.has_game_password(): @@ -374,7 +376,7 @@ def get_player_identity(self, username): 'player_key': player_key } else: - warning("Couldn't find identify player: {}".format(username)) + warning(_("Couldn't find identify player: {}").format(username)) return { 'ip': None, 'country': "Unknown", diff --git a/magicked_admin/web_admin/web_interface.py b/magicked_admin/web_admin/web_interface.py index fd722874..4327ce9e 100644 --- a/magicked_admin/web_admin/web_interface.py +++ b/magicked_admin/web_admin/web_interface.py @@ -1,11 +1,13 @@ import time from hashlib import sha1 - +import gettext import requests from lxml import html from utils import debug, die, info, warning +_ = gettext.gettext + class WebInterface(object): def __init__(self, address, username, password, server_name="unnamed"): @@ -54,7 +56,7 @@ def __get(self, session, url, retry_interval=6, login=False): if not login: if "hashAlg" in response.text: - info("Session killed, renewing!") + info(_("Session killed, renewing!")) self.__session = self.__new_session() else: return response @@ -93,7 +95,7 @@ def __post(self, session, url, payload, retry_interval=6, login=False): if not login: if "hashAlg" in response.text: - info("Session killed, renewing!") + info(_("Session killed, renewing!")) self.__session = self.__new_session() else: return response @@ -116,12 +118,12 @@ def __post(self, session, url, payload, retry_interval=6, login=False): def __sleep(self): if not self.__sleeping: - info("Web admin not responding, sleeping") + info(_("Web admin not responding, sleeping")) self.__sleeping = True def __wake(self): if self.__sleeping: - info("Web admin is back, resuming") + info(_("Web admin is back, resuming")) self.__sleeping = False def __new_session(self): @@ -157,16 +159,16 @@ def __new_session(self): if "hashAlg" in response.text \ or "Exceeded login attempts" in response.text: # TODO Expand on handling here, should gracefully terminate - die("Login failure, bad credentials or login attempts exceeded.", - pause=True) + die(_("Login failure, bad credentials or login attempts " + "exceeded."), pause=True) if "" in response.text: self.ma_installed = True - info("Detected KF2-MA install on server.") + info(_("Detected KF2-MA install on server.")) else: pass - warning("KF2-MA install not detected on server side! " - "Consequently, only Survival mode will function fully.") + warning(_("KF2-MA install not detected on server side! " + "Consequently, only Survival mode will function fully.")) return session