From a24fa948705117fd52b99a6dff16f18995bd858c Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Wed, 10 Jul 2024 09:56:33 +0200 Subject: [PATCH 1/8] Update commands.md --- docs/commands.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 68b7c495..ba533d50 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -526,18 +526,19 @@ * **musiclist\_remove** `` `` `` - Allow you to remove a song from a musiclist! - Remember to insert a file extension in ``. For songs without extension, put in .music. -* **musiclist\_save** `` `[MusiclistName]` +* **musiclist\_save** `` `[MusiclistName]` `[read_only]` - Allow you to save a musiclist on server list! - If the musiclist you're editing is already in the server list, you don't have to add `[MusiclistName]` + - If `[read_only]` is a parameter in the arguments then none can rewrite the current musiclist ## Battle * **choose\_fighter** `` - Allow you to choose a fighter from the list of the server. - You will receive its stats and its moves. * **info\_fighter** - Send info about your fighter. -* **create\_fighter** `` `` `` `` `` `` `` +* **create\_fighter** `` `` `` `` `` `` `` `` - Allow you to create a fighter and to customize its stats. -* **create\_move** `` `` `` `` `` +* **create\_move** `` `` `` `` `` `` - Allow you to create a move for a fighter. - You have to choose a fighter first! - MovesType: Atk or Spa @@ -550,7 +551,7 @@ - You have to choose a fighter first! * **battle\_config** `` `` - Allow you to customize some battle settings. - - parameters: paralysis_rate, critical_rate, critical_bonus, bonus_malus, poison_damage + - parameters: paralysis_rate, critical_rate, critical_bonus, bonus_malus, poison_damage, show hp, min_multishot, max_multishot, burn_damage, freeze_damage, confusion_rate, enraged_bonus, stolen_stat * **fight** - Allow you to join the battle! * **use\_move** `` `` From 665a862d26b4b4e06ab01b3fa378ccdfd44a0137 Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Sat, 13 Jul 2024 10:54:42 +0200 Subject: [PATCH 2/8] Update commands.md --- docs/commands.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index ba533d50..7f4e77d6 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -342,11 +342,12 @@ * **hub** `[id/name]` - List hubs, or go to another hub. ### Saving/loading -* **save\_hub** `` - - Save the current Hub in the server's `storage/hubs/.yaml` file. +* **save\_hub** `` `[read_only]` + - Save the current Hub in the server's `storage/hubs/read_only/.yaml` or `storage/hubs/write_read/.yaml` file. - If blank and you're a mod, it will save to server's `config/areas_new.yaml` for the server owner to approve. + - If `[read_only]` is a parameter in the arguments then none can rewrite the current musiclist * **load\_hub** `` - - Load Hub data from the server's `storage/hubs/.yaml` file. + - Load Hub data from the server's `storage/hubs/read_only/.yaml` or `storage/hubs/write_read/.yaml` file. - If blank and you're a mod, it will reload the server's `config/areas.yaml`. * **overlay\_hub** `` - Overlay Hub data from the server's `storage/hubs/.yaml` file on top of the current hub, only applying properties defined in that yaml. @@ -569,6 +570,18 @@ - Allow you to skip the turn * **force\_skip\_move** `` - Force a fighter to skip the turn +* **create\_guild** `` + - Allow you to create a guild +* **info\_guild** + - Send info about your guild +* **join\_guild** `` + - Allow the guild leader to let a fighter to join the guild +* **leave\_guild** `` + - Allow you to leave your current guid +* **close\_guild** `` + - Allow GM to close all guilds if arg is "", or to close a specific guild is arg is GuildName +* **battle\_effects** + - Show all available battle effects ## In-Character Commands * **/a** `[id(s)]` `[msg]` - Put this in the In-Character chat. From cf255cff48dbad6d4119d90368073fd0e77cad89 Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Sat, 13 Jul 2024 10:55:20 +0200 Subject: [PATCH 3/8] Update commands.md --- docs/commands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/commands.md b/docs/commands.md index 7f4e77d6..790a605b 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -345,7 +345,7 @@ * **save\_hub** `` `[read_only]` - Save the current Hub in the server's `storage/hubs/read_only/.yaml` or `storage/hubs/write_read/.yaml` file. - If blank and you're a mod, it will save to server's `config/areas_new.yaml` for the server owner to approve. - - If `[read_only]` is a parameter in the arguments then none can rewrite the current musiclist + - If `[read_only]` is a parameter in the arguments then none can rewrite the current hub. * **load\_hub** `` - Load Hub data from the server's `storage/hubs/read_only/.yaml` or `storage/hubs/write_read/.yaml` file. - If blank and you're a mod, it will reload the server's `config/areas.yaml`. From bea1fc5700e8d47f89caaf15052266a0c3599501 Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Mon, 15 Jul 2024 19:37:04 +0200 Subject: [PATCH 4/8] Update commands.md --- docs/commands.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 790a605b..ae426601 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -343,11 +343,11 @@ - List hubs, or go to another hub. ### Saving/loading * **save\_hub** `` `[read_only]` - - Save the current Hub in the server's `storage/hubs/read_only/.yaml` or `storage/hubs/write_read/.yaml` file. + - Save the current Hub in the server's `storage/hubs/read_only/.yaml` or `storage/hubs/.yaml` file. - If blank and you're a mod, it will save to server's `config/areas_new.yaml` for the server owner to approve. - If `[read_only]` is a parameter in the arguments then none can rewrite the current hub. * **load\_hub** `` - - Load Hub data from the server's `storage/hubs/read_only/.yaml` or `storage/hubs/write_read/.yaml` file. + - Load Hub data from the server's `storage/hubs/read_only/.yaml` or `storage/hubs/.yaml` file. - If blank and you're a mod, it will reload the server's `config/areas.yaml`. * **overlay\_hub** `` - Overlay Hub data from the server's `storage/hubs/.yaml` file on top of the current hub, only applying properties defined in that yaml. From 68905401d65e0d559649ffc83f018e3e59a568a9 Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Fri, 23 Aug 2024 21:01:16 +0200 Subject: [PATCH 5/8] add italian translation --- translations/it.yaml | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 translations/it.yaml diff --git a/translations/it.yaml b/translations/it.yaml new file mode 100644 index 00000000..0a7d064a --- /dev/null +++ b/translations/it.yaml @@ -0,0 +1,80 @@ +admin.py: + ooc_cmd_motd: + This command doesn't take any arguments: "Questo comando non ha bisogno di argomenti" + ooc_cmd_help: + No such command or submodule ({arg}) has been found in the help docs.: "Nessun commando o sottomodulo ({arg}) e' stato trovato nel documento 'help'" + ooc_cmd_kick: + You must specify a target. Use /kick [reason]: "Devi specificare il target. Usa /kick [motivo]" + "{raw_ipid} does not look like a valid IPID.": "{raw_ipid} non sembra un valido IPID." + "{c.showname} was kicked.": "{c.showname} e' stato kickato" + No targets with the IPID {ipid} were found.: "Nessun target con l'IPID {ipid} e' stato trovato" + kickban: + Not enough arguments.: "Non ci sono abbastanza argomenti." + Invalid ban duration.: "Durata del ban non valida." + 'Ambiguous input: {arg}\nPlease wrap your arguments " " in quotes.': "L'input e' ambiguo: {arg}\nProva a scrivere il tuo argomento usando le '' virgolette." + "{raw_ipid} does not look like a valid IPID.": "{raw_ipid} non sembra un valido IPID" + "{num} clients were kicked.": "{num} giocatori sono stati kickati." + "{ipid} was banned. Ban ID: {ban_id}": "{ipid} e' stato bannato. Ban ID: {ban_id}" + ooc_cmd_unban: + You must specify a target. Use /unban : "Devi specificare il target. Usa /unban " + Attempting to lift {num} ban(s)...: "Revocando {num} ban..." + Removed ban ID {ban_id}.: "Rimuovendo ban ID {ban_id}" + "{ban_id} is not on the ban list.": "{ban_id} non e' nella ban list." + ooc_cmd_mute: + You must specify a target. Use /mute .: "Devi specificare il target. Usa /mute " + Attempting to mute {num} IPIDs.: "Mutando {num} IPID" + Muted the IPID : "Mutato l'IPID" + "'s following clients:": "Dei seguenti giocatori" + No targets found. Use /mute ... for mute.: "Nessun target trovato. Usa /mute ... per mutare." + "{raw_ipid} does not look like a valid IPID.": "{raw_ipid} non sembra un valido IPID." + ooc_cmd_unmute: + You must specify a target.: "Devi specificare il target." + Attempting to unmute {num} IPIDs.: "Smutando {num} IPID" + "Unmuted the IPID ${ipid}'s following clients:": "Smutando l'IPID {ipid} dei seguenti giocatori" + No targets found. Use /unmute ... for unmute.: "Nessun target trovato. Usa /unmute ... per smutare" + "{raw_ipid} does not look like a valid IPID.": "{raw_ipid} non sembra un valido IPID" + ooc_cmd_login: + You must specify the password.: "Devi specificare la password." + Logged in as a moderator.: "Loggato come moderatore." + ooc_cmd_refresh: + This command does not take in any arguments!: "Questo comando non ha bisogno di argomenti!" + You have reloaded the server.: "Hai ricaricato il server." + ooc_cmd_unmod: + You're no longer a mod.: "Non sei piĆ¹ moderatore." + ooc_cmd_ooc_mute: + You must specify a target. Use /ooc_mute .: "Devi specificare il target. Usa /ooc_mute ." + Targets not found. Use /ooc_mute .: "Target non trovato. Usa /ooc_mute ." + Muted {num} existing client(s).: "Mutati {num} giocatori esistenti." + ooc_cmd_ooc_unmute: + You must specify a target. Use /ooc_unmute .: "Devi specificare il target. Usa /ooc_unmute ." + Targets not found. Use /ooc_unmute .: "Target non trovato. Usa /ooc_unmute ." + Unmuted {num} existing client(s).: "Smutati {num} giocatori esistenti." + ooc_cmd_bans: + "Last 5 bans:\n": "Ultimi 5 ban\n" + "{time}: {ban.banned_by_name} ({ban.banned_by}) issued ban ": "{time}: {ban.banned_by_name} ({ban.banned_by}) ha messo il seguente ban" + ooc_cmd_baninfo: + You must specify an ID.: "Devi specificare un ID." + Incorrect lookup type.: "Hai sbagliato il tipo di ricerca." + No ban found for this ID.: "Nessun ban trovato per questo ID." + "Affected IPIDs: ": "IPID interessati: " + "Affected HDIDs: ": "HDID interessati: " + 'Reason: "{reason}"\n': 'Motivo: "{reason}"\n' + "Banned by: {banned_by_name} ({banned_by})\n": "Bannato da: {banned_by_name} ({banned_by})\n" + "Banned on: {ban_date_format} ({ban_date})\n": "Bannato nella data: {ban_date_format} ({ban_date})\n" + "Unban date: {unban_date_format} ({unban_date})": "Data Sban: {unban_date_format} ({unban_date})" + "Unban date: N/A": "Data Sban: N/A" + ooc_cmd_time: + This command takes no arguments: "Questo comando non ha bisogno di argomenti" + "The current time in UTC (aka GMT) is:\n[": "L'ora esatta in UTC (aka GMT) e':\n[" + ooc_cmd_whois: + "WHOIS lookup for {arg}:": "ChiE' ricerca per {arg}:" + "\nMatched {num} online clients.": "\n{num} giocatori online abbinati." + ooc_cmd_restart: + no: "no" + Restarting the server...: "Il server sta restartando..." + ooc_cmd_myid: + This command takes no arguments: "Questo comando non ha bisogno di argomenti" + "You are: [{id}] " : "Tu sei [{id}] " + ooc_cmd_multiclients: + "Clients belonging to {arg}:": "Giocatori che appartengo a {arg}" + \nMatched {num} online clients.: "\n{num} giocatori online abbinati." From 154b0c71ef8d7db8bcc3a38a75cd422f8914565c Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Fri, 23 Aug 2024 21:02:35 +0200 Subject: [PATCH 6/8] add languages in config --- config_sample/config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config_sample/config.yaml b/config_sample/config.yaml index 34a77ebd..654d3b65 100644 --- a/config_sample/config.yaml +++ b/config_sample/config.yaml @@ -7,6 +7,10 @@ # be used by other players. hostname: H +# Choose the default languages for your server +# Available Languages: eng, it +language: eng + # Max number of player slots to be made. The player limit is not actually # enforced, but bad things are supposed to happen if this is exceeded. playerlimit: 100 From ad1421f7ce39f4ea0458c7db05689763b946c583 Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Fri, 23 Aug 2024 21:04:29 +0200 Subject: [PATCH 7/8] add translator on the server --- server/lang.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 server/lang.py diff --git a/server/lang.py b/server/lang.py new file mode 100644 index 00000000..122484b8 --- /dev/null +++ b/server/lang.py @@ -0,0 +1,45 @@ +import inspect +import sys +import yaml + +try: + with open("config/config.yaml", "r", encoding="utf-8") as cfg: + config = yaml.safe_load(cfg) +except OSError: + print("error: config/config.yaml wasn't found.") + print("You are either running from the wrong directory, or") + print("you forgot to rename config_sample (read the instructions).") + sys.exit(1) + +supported_languages = ["eng", "it"] +if "language" not in config or config["language"] not in supported_languages: + config["language"] = "eng" + +if config["language"] != "eng": + try: + with open( + f"translations/{config['language']}.yaml", "r", encoding="latin-1" + ) as translation: + server_translation = yaml.safe_load(translation) + except OSError: + print(f"error: translation wasn't found.") + print("You are either running from the wrong directory") + sys.exit(1) + +else: + server_translation = None + + +def tr(string): + if server_translation is None: + return string + filename = inspect.stack()[1][1].split("\\")[-1] + function_name = inspect.stack()[1][3] + if ( + filename in server_translation + and function_name in server_translation[filename] + and string in server_translation[filename][function_name] + ): + return server_translation[filename][function_name][string] + else: + return string From 9db7697fee3e717ba5e6b3b843956f8a6fad9b8b Mon Sep 17 00:00:00 2001 From: UnDeviato Date: Fri, 23 Aug 2024 21:05:38 +0200 Subject: [PATCH 8/8] rewrite admin.py so that strings can be translated --- server/commands/admin.py | 119 ++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/server/commands/admin.py b/server/commands/admin.py index e9b12148..359171a3 100644 --- a/server/commands/admin.py +++ b/server/commands/admin.py @@ -6,6 +6,7 @@ from server import database from server.constants import TargetType from server.exceptions import ClientError, ServerError, ArgumentError +from server.lang import tr import asyncio from . import mod_only, list_commands, list_submodules, help @@ -42,7 +43,7 @@ def ooc_cmd_motd(client, arg): Usage: /motd """ if len(arg) != 0: - raise ArgumentError("This command doesn't take any arguments") + raise ArgumentError(tr("This command doesn't take any arguments")) client.send_motd() @@ -54,7 +55,7 @@ def ooc_cmd_help(client, arg): import inspect if arg == "": - msg = inspect.cleandoc( + msg = inspect.cleandoc(tr( """ Welcome to tsuserver3! You can use /help on any known command to get up-to-date help on it. @@ -67,7 +68,7 @@ def ooc_cmd_help(client, arg): Available Categories: """ - ) + )) msg += "\n" msg += list_submodules() client.send_ooc(msg) @@ -79,12 +80,12 @@ def ooc_cmd_help(client, arg): client.send_ooc(help(f"ooc_cmd_{arg}")) except AttributeError: try: - msg = f'Submodule "{arg}" commands:\n\n' + msg = tr('Submodule "{arg}" commands:\n\n').format(arg=arg) msg += list_commands(arg) client.send_ooc(msg) except AttributeError: client.send_ooc( - f"No such command or submodule ({arg}) has been found in the help docs." + tr("No such command or submodule ({arg}) has been found in the help docs.").format(arg=arg) ) @@ -99,7 +100,7 @@ def ooc_cmd_kick(client, arg): """ if len(arg) == 0: raise ArgumentError( - "You must specify a target. Use /kick [reason]") + tr("You must specify a target. Use /kick [reason]")) elif arg[0] == "*": targets = [c for c in client.area.clients if c != client] elif arg[0] == "**": @@ -113,7 +114,7 @@ def ooc_cmd_kick(client, arg): try: ipid = int(raw_ipid) except Exception: - raise ClientError(f"{raw_ipid} does not look like a valid IPID.") + raise ClientError(tr("{raw_ipid} does not look like a valid IPID.").format(raw_ipid=raw_ipid)) targets = client.server.client_manager.get_targets( client, TargetType.IPID, ipid, False ) @@ -123,12 +124,12 @@ def ooc_cmd_kick(client, arg): for c in targets: database.log_misc("kick", client, target=c, data={"reason": reason}) - client.send_ooc(f"{c.showname} was kicked.") + client.send_ooc(tr("{showname} was kicked.").format(showname=c.showname)) c.send_command("KK", reason) c.disconnect() client.server.webhooks.kick(c.ipid, reason, client, c.char_name) else: - client.send_ooc(f"No targets with the IPID {ipid} were found.") + client.send_ooc(tr("No targets with the IPID {ipid} were found.").format(ipid=ipid)) def ooc_cmd_ban(client, arg): @@ -154,7 +155,7 @@ def ooc_cmd_banhdid(client, arg): def kickban(client, arg, ban_hdid): args = shlex.split(arg) if len(args) < 2: - raise ArgumentError("Not enough arguments.") + raise ArgumentError(tr("Not enough arguments.")) elif len(args) == 2: reason = None ban_id = None @@ -172,18 +173,18 @@ def kickban(client, arg, ban_hdid): else: duration = pytimeparse.parse(args[2], granularity="hours") if duration is None: - raise ArgumentError("Invalid ban duration.") + raise ArgumentError(tr("Invalid ban duration.")) unban_date = arrow.get().shift(seconds=duration).datetime else: raise ArgumentError( - f"Ambiguous input: {arg}\nPlease wrap your arguments " "in quotes." + tr("Ambiguous input: {arg}\nPlease wrap your arguments " "in quotes.") ) try: raw_ipid = args[0] ipid = int(raw_ipid) except ValueError: - raise ClientError(f"{raw_ipid} does not look like a valid IPID.") + raise ClientError(tr("{raw_ipid} does not look like a valid IPID.").format(raw_ipid=raw_ipid)) ban_id = database.ban( ipid, @@ -211,8 +212,8 @@ def kickban(client, arg, ban_hdid): char = c.char_name database.log_misc("ban", client, target=c, data={"reason": reason}) - client.send_ooc(f"{len(targets)} clients were kicked.") - client.send_ooc(f"{ipid} was banned. Ban ID: {ban_id}") + client.send_ooc(tr("{num} clients were kicked.").format(num=len(targets))) + client.send_ooc(tr("{ipid} was banned. Ban ID: {ban_id}").format(ipid=ipid, ban_id=ban_id)) client.server.webhooks.ban( ipid, ban_id, reason, client, hdid, char, unban_date) @@ -225,15 +226,15 @@ def ooc_cmd_unban(client, arg): """ if len(arg) == 0: raise ArgumentError( - "You must specify a target. Use /unban ") + tr("You must specify a target. Use /unban ")) args = list(arg.split(" ")) - client.send_ooc(f"Attempting to lift {len(args)} ban(s)...") + client.send_ooc(tr("Attempting to lift {num} ban(s)...").format(num=len(args))) for ban_id in args: if database.unban(ban_id): - client.send_ooc(f"Removed ban ID {ban_id}.") + client.send_ooc(tr("Removed ban ID {ban_id}.").format(ban_id=ban_id)) client.server.webhooks.unban(ban_id, client) else: - client.send_ooc(f"{ban_id} is not on the ban list.") + client.send_ooc(tr("{ban_id} is not on the ban list.").format(ban_id=ban_id)) database.log_misc("unban", client, data={"id": ban_id}) @@ -246,7 +247,7 @@ def ooc_cmd_mute(client, arg): if len(arg) == 0: raise ArgumentError("You must specify a target. Use /mute .") args = list(arg.split(" ")) - client.send_ooc(f"Attempting to mute {len(args)} IPIDs.") + client.send_ooc(tr("Attempting to mute {num} IPIDs.").format(num=len(args))) for raw_ipid in args: if raw_ipid.isdigit(): ipid = int(raw_ipid) @@ -254,7 +255,7 @@ def ooc_cmd_mute(client, arg): client, TargetType.IPID, ipid, False ) if clients: - msg = "Muted the IPID " + str(ipid) + "'s following clients:" + msg = tr("Muted the IPID ")+ str(ipid) + tr("'s following clients:") for c in clients: c.is_muted = True database.log_misc("mute", client, target=c) @@ -264,10 +265,10 @@ def ooc_cmd_mute(client, arg): client.send_ooc(msg) else: client.send_ooc( - "No targets found. Use /mute ... for mute." + tr("No targets found. Use /mute ... for mute.") ) else: - client.send_ooc(f"{raw_ipid} does not look like a valid IPID.") + client.send_ooc(tr("{raw_ipid} does not look like a valid IPID.").format(raw_ipid=raw_ipid)) @mod_only() @@ -277,9 +278,9 @@ def ooc_cmd_unmute(client, arg): Usage: /unmute """ if len(arg) == 0: - raise ArgumentError("You must specify a target.") + raise ArgumentError(tr("You must specify a target.")) args = list(arg.split(" ")) - client.send_ooc(f"Attempting to unmute {len(args)} IPIDs.") + client.send_ooc(tr("Attempting to unmute {num} IPIDs.").format(num=len(args))) for raw_ipid in args: if raw_ipid.isdigit(): ipid = int(raw_ipid) @@ -287,7 +288,7 @@ def ooc_cmd_unmute(client, arg): client, TargetType.IPID, ipid, False ) if clients: - msg = f"Unmuted the IPID ${str(ipid)}'s following clients:" + msg = tr("Unmuted the IPID ${ipid}'s following clients:").format(ipid = str(ipid)) for c in clients: c.is_muted = False database.log_misc("unmute", client, target=c) @@ -297,10 +298,10 @@ def ooc_cmd_unmute(client, arg): client.send_ooc(msg) else: client.send_ooc( - "No targets found. Use /unmute ... for unmute." + tr("No targets found. Use /unmute ... for unmute.") ) else: - client.send_ooc(f"{raw_ipid} does not look like a valid IPID.") + client.send_ooc(tr("{raw_ipid} does not look like a valid IPID.").format(raw_ipid=raw_ipid)) def ooc_cmd_login(client, arg): @@ -309,7 +310,7 @@ def ooc_cmd_login(client, arg): Usage: /login """ if len(arg) == 0: - raise ArgumentError("You must specify the password.") + raise ArgumentError(tr("You must specify the password.")) login_name = None try: login_name = client.auth_mod(arg) @@ -321,7 +322,7 @@ def ooc_cmd_login(client, arg): client.area.broadcast_area_list(client) client.area.broadcast_evidence_list() - client.send_ooc("Logged in as a moderator.") + client.send_ooc(tr("Logged in as a moderator.")) client.server.webhooks.login(client, login_name) database.log_misc("login", client, data={"profile": login_name}) @@ -334,12 +335,12 @@ def ooc_cmd_refresh(client, arg): Usage: /refresh """ if len(arg) > 0: - raise ClientError("This command does not take in any arguments!") + raise ClientError(tr("This command does not take in any arguments!")) else: try: client.server.refresh() database.log_misc("refresh", client) - client.send_ooc("You have reloaded the server.") + client.send_ooc(tr("You have reloaded the server.")) except ServerError: raise @@ -372,7 +373,7 @@ def ooc_cmd_unmod(client, arg): client.area.broadcast_area_list(client) client.area.broadcast_evidence_list() - client.send_ooc("You're no longer a mod.") + client.send_ooc(tr("You're no longer a mod.")) @mod_only() @@ -383,16 +384,16 @@ def ooc_cmd_ooc_mute(client, arg): """ if len(arg) == 0: raise ArgumentError( - "You must specify a target. Use /ooc_mute .") + tr("You must specify a target. Use /ooc_mute .")) targets = client.server.client_manager.get_targets( client, TargetType.OOC_NAME, arg, False ) if not targets: - raise ArgumentError("Targets not found. Use /ooc_mute .") + raise ArgumentError(tr("Targets not found. Use /ooc_mute .")) for target in targets: target.is_ooc_muted = True database.log_area("ooc_mute", client, client.area, target=target) - client.send_ooc("Muted {} existing client(s).".format(len(targets))) + client.send_ooc(tr("Muted {num} existing client(s).").format(num = len(targets))) @mod_only() @@ -403,14 +404,14 @@ def ooc_cmd_ooc_unmute(client, arg): """ if len(arg) == 0: raise ArgumentError( - "You must specify a target. Use /ooc_unmute .") + tr("You must specify a target. Use /ooc_unmute .")) targets = client.server.client_manager.get_ooc_muted_clients() if not targets: - raise ArgumentError("Targets not found. Use /ooc_unmute .") + raise ArgumentError(tr("Targets not found. Use /ooc_unmute .")) for target in targets: target.is_ooc_muted = False database.log_area("ooc_unmute", client, client.area, target=target) - client.send_ooc("Unmuted {} existing client(s).".format(len(targets))) + client.send_ooc(tr("Unmuted {num} existing client(s).").format(num = len(targets))) @mod_only() @@ -423,7 +424,7 @@ def ooc_cmd_bans(client, _arg): for ban in database.recent_bans(): time = arrow.get(ban.ban_date).humanize() msg += ( - f"{time}: {ban.banned_by_name} ({ban.banned_by}) issued ban " + tr("{time}: {banned_by_name} ({banned_by}) issued ban ").format(time=time, banned_by_name=ban.banned_by_name, banned_by=ban.banned_by), f"{ban.ban_id} ('{ban.reason}')\n" ) client.send_ooc(msg) @@ -438,33 +439,33 @@ def ooc_cmd_baninfo(client, arg): """ args = arg.split(" ") if len(arg) == 0: - raise ArgumentError("You must specify an ID.") + raise ArgumentError(tr("You must specify an ID.")) elif len(args) == 1: lookup_type = "ban_id" else: lookup_type = args[1] if lookup_type not in ("ban_id", "ipid", "hdid"): - raise ArgumentError("Incorrect lookup type.") + raise ArgumentError(tr("Incorrect lookup type.")) ban = database.find_ban(**{lookup_type: args[0]}) if ban is None: - client.send_ooc("No ban found for this ID.") + client.send_ooc(tr("No ban found for this ID.")) else: msg = f"Ban ID: {ban.ban_id}\n" - msg += "Affected IPIDs: " + \ + msg += tr("Affected IPIDs: ") + \ ", ".join([str(ipid) for ipid in ban.ipids]) + "\n" - msg += "Affected HDIDs: " + ", ".join(ban.hdids) + "\n" - msg += f'Reason: "{ban.reason}"\n' - msg += f"Banned by: {ban.banned_by_name} ({ban.banned_by})\n" + msg += tr("Affected HDIDs: ") + ", ".join(ban.hdids) + "\n" + msg += tr('Reason: "{reason}"\n').format(reason=ban.reason) + msg += tr("Banned by: {banned_by_name} ({banned_by})\n").format(banned_by_name=ban.banned_by_name, banned_by=ban.banned_by) ban_date = arrow.get(ban.ban_date) - msg += f"Banned on: {ban_date.format()} ({ban_date.humanize()})\n" + msg += tr("Banned on: {ban_date_format} ({ban_date})\n").format(ban_date_format=ban_date.format(), ban_date=ban_date.humanize()) if ban.unban_date is not None: unban_date = arrow.get(ban.unban_date) - msg += f"Unban date: {unban_date.format()} ({unban_date.humanize()})" + msg += tr("Unban date: {unban_date_format} ({unban_date})").format(unban_date_format=unban_date.format(), unban_date=unban_date.humanize()) else: - msg += "Unban date: N/A" + msg += tr("Unban date: N/A") client.send_ooc(msg) @@ -474,10 +475,10 @@ def ooc_cmd_time(client, arg): Usage: /time """ if len(arg) > 0: - raise ArgumentError("This command takes no arguments") + raise ArgumentError(tr("This command takes no arguments")) from time import asctime, gmtime, time - msg = "The current time in UTC (aka GMT) is:\n[" + msg = tr("The current time in UTC (aka GMT) is:\n[") msg += asctime(gmtime(time())) msg += "]" client.send_ooc(msg) @@ -500,7 +501,7 @@ def ooc_cmd_whois(client, arg): ): found_clients.add(c) - info = f"WHOIS lookup for {arg}:" + info = tr("WHOIS lookup for {arg}:").format(arg=arg) for c in found_clients: info += f"\n[{c.id}] " if c.showname != c.char_name: @@ -510,7 +511,7 @@ def ooc_cmd_whois(client, arg): info += f" ({c.ipid})" if c.name != "": info += f": {c.name}" - info += f"\nMatched {len(found_clients)} online clients." + info += tr("\nMatched {num} online clients.").format(num=len(found_clients)) client.send_ooc(info) @@ -521,10 +522,10 @@ def ooc_cmd_restart(client, arg): Usage: /restart """ if arg != client.server.config["restartpass"]: - raise ArgumentError("no") + raise ArgumentError(tr("no")) print(f"!!!{client.name} called /restart!!!") client.server.send_all_cmd_pred( - "CT", "WARNING", "Restarting the server...") + "CT", "WARNING", tr("Restarting the server...")) asyncio.get_running_loop().stop() @@ -535,7 +536,7 @@ def ooc_cmd_myid(client, arg): """ if len(arg) > 0: raise ArgumentError("This command takes no arguments") - info = f"You are: [{client.id}] " + info = tr("You are: [{id}] ").format(id=client.id) if client.showname != client.char_name: info += f'"{client.showname}" ({client.char_name})' else: @@ -559,7 +560,7 @@ def ooc_cmd_multiclients(client, arg): found_clients.add(c) found_clients |= set(client.server.client_manager.get_multiclients(c.ipid, c.hdid)) - info = f"Clients belonging to {arg}:" + info = tr("Clients belonging to {arg}:").format(arg=arg) for c in found_clients: info += f"\n[{c.id}] " if c.showname != c.char_name: @@ -569,5 +570,5 @@ def ooc_cmd_multiclients(client, arg): info += f" ({c.ipid})" if c.name != "": info += f": {c.name}" - info += f"\nMatched {len(found_clients)} online clients." + info += tr("\nMatched {num} online clients.").format(num=len(found_clients)) client.send_ooc(info)