From af0eaed28a5be550fa90fb30e7a721512c523c74 Mon Sep 17 00:00:00 2001 From: trhr Date: Wed, 15 Apr 2020 21:21:16 -0500 Subject: [PATCH 1/6] i18n --- evennia/accounts/accounts.py | 46 ++++++++++++++++----------------- evennia/accounts/bots.py | 5 ++-- evennia/help/manager.py | 2 +- evennia/objects/admin.py | 4 +-- evennia/utils/validatorfuncs.py | 5 ++-- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 397ea287b6..24c551fdbb 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -275,11 +275,11 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): raise RuntimeError("Session not found") if self.get_puppet(session) == obj: # already puppeting this object - self.msg("You are already puppeting this object.") + self.msg(_("You are already puppeting this object.") return if not obj.access(self, "puppet"): # no access - self.msg(f"You don't have permission to puppet '{obj.key}'.") + self.msg(_(f"You don't have permission to puppet '{obj.key}'.") return if obj.account: # object already puppeted @@ -295,12 +295,12 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): else: txt1 = f"Taking over |c{obj.name}|n from another of your sessions." txt2 = f"|c{obj.name}|n|R is now acted from another of your sessions.|n" - self.msg(txt1, session=session) - self.msg(txt2, session=obj.sessions.all()) + self.msg(_(txt1), session=session) + self.msg(_(txt2), session=obj.sessions.all()) self.unpuppet_object(obj.sessions.get()) elif obj.account.is_connected: # controlled by another account - self.msg(f"|c{obj.key}|R is already puppeted by another Account.") + self.msg(_(f"|c{obj.key}|R is already puppeted by another Account.")) return # do the puppeting @@ -496,7 +496,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): # See if authentication is currently being throttled if ip and LOGIN_THROTTLE.check(ip): - errors.append("Too many login failures; please try again in a few minutes.") + errors.append(_("Too many login failures; please try again in a few minutes.")) # With throttle active, do not log continued hits-- it is a # waste of storage and can be abused to make your logs harder to @@ -508,8 +508,8 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if banned: # this is a banned IP or name! errors.append( - "|rYou have been banned and cannot continue from here." - "\nIf you feel this ban is in error, please email an admin.|x" + _("|rYou have been banned and cannot continue from here." + "\nIf you feel this ban is in error, please email an admin.|x") ) logger.log_sec(f"Authentication Denied (Banned): {username} (IP: {ip}).") LOGIN_THROTTLE.update(ip, "Too many sightings of banned artifact.") @@ -519,7 +519,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): account = authenticate(username=username, password=password) if not account: # User-facing message - errors.append("Username and/or password is incorrect.") + errors.append(_("Username and/or password is incorrect.")) # Log auth failures while throttle is inactive logger.log_sec(f"Authentication Failure: {username} (IP: {ip}).") @@ -688,7 +688,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): ip = kwargs.get("ip", "") if ip and CREATION_THROTTLE.check(ip): errors.append( - "You are creating too many accounts. Please log into an existing account." + _("You are creating too many accounts. Please log into an existing account.") ) return None, errors @@ -717,8 +717,8 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if banned: # this is a banned IP or name! string = ( - "|rYou have been banned and cannot continue from here." - "\nIf you feel this ban is in error, please email an admin.|x" + _("|rYou have been banned and cannot continue from here." + "\nIf you feel this ban is in error, please email an admin.|x") ) errors.append(string) return None, errors @@ -733,7 +733,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): except Exception as e: errors.append( - "There was an error creating the Account. If this problem persists, contact an admin." + _("There was an error creating the Account. If this problem persists, contact an admin.") ) logger.log_trace() return None, errors @@ -785,7 +785,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, # we won't see any errors at all. - errors.append("An error occurred. Please e-mail an admin if the problem persists.") + errors.append(_("An error occurred. Please e-mail an admin if the problem persists.")) logger.log_trace() # Update the throttle to indicate a new account was created from this IP @@ -1260,14 +1260,14 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): try: self.puppet_object(session, self.db._last_puppet) except RuntimeError: - self.msg("The Character does not exist.") + self.msg(_("The Character does not exist.")) return elif _MULTISESSION_MODE == 1: # in this mode all sessions connect to the same puppet. try: self.puppet_object(session, self.db._last_puppet) except RuntimeError: - self.msg("The Character does not exist.") + self.msg(_("The Character does not exist.")) return elif _MULTISESSION_MODE in (2, 3): # In this mode we by default end up at a character selection @@ -1305,7 +1305,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): """ reason = f" ({reason if reason else ''})" - self._send_to_connect_channel(f"|R{self.key} disconnected{reason}|n") + self._send_to_connect_channel(_(f"|R{self.key} disconnected{reason}|n")) def at_post_disconnect(self, **kwargs): """ @@ -1411,7 +1411,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if hasattr(target, "return_appearance"): return target.return_appearance(self) else: - return "{} has no in-game appearance.".format(target) + return _(f"{target} has no in-game appearance.") else: # list of targets - make list to disconnect from db characters = list(tar for tar in target if tar) if target else [] @@ -1454,7 +1454,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if is_su or len(characters) < charmax: if not characters: result.append( - "\n\n You don't have any characters yet. See |whelp @charcreate|n for creating one." + _("\n\n You don't have any characters yet. See |whelp @charcreate|n for creating one.") ) else: result.append("\n |w@charcreate [=description]|n - create new character") @@ -1534,7 +1534,7 @@ class DefaultGuest(DefaultAccount): # check if guests are enabled. if not settings.GUEST_ENABLED: - errors.append("Guest accounts are not enabled on this server.") + errors.append(_("Guest accounts are not enabled on this server.")) return None, errors try: @@ -1544,7 +1544,7 @@ class DefaultGuest(DefaultAccount): username = name break if not username: - errors.append("All guest accounts are in use. Please try again later.") + errors.append(_("All guest accounts are in use. Please try again later.")) if ip: LOGIN_THROTTLE.update(ip, "Too many requests for Guest access.") return None, errors @@ -1572,7 +1572,7 @@ class DefaultGuest(DefaultAccount): # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, # we won't see any errors at all. - errors.append("An error occurred. Please e-mail an admin if the problem persists.") + errors.append(_("An error occurred. Please e-mail an admin if the problem persists.")) logger.log_trace() return None, errors @@ -1589,7 +1589,7 @@ class DefaultGuest(DefaultAccount): overriding the call (unused by default). """ - self._send_to_connect_channel(f"|G{self.key} connected|n") + self._send_to_connect_channel(_(f"|G{self.key} connected|n")) self.puppet_object(session, self.db._last_puppet) def at_server_shutdown(self): diff --git a/evennia/accounts/bots.py b/evennia/accounts/bots.py index 455e10b629..1c1fc7d300 100644 --- a/evennia/accounts/bots.py +++ b/evennia/accounts/bots.py @@ -10,6 +10,7 @@ from evennia.accounts.accounts import DefaultAccount from evennia.scripts.scripts import DefaultScript from evennia.utils import search from evennia.utils import utils +from django.utils.translation import gettext as _ _IDLE_TIMEOUT = settings.IDLE_TIMEOUT @@ -328,7 +329,7 @@ class IRCBot(Bot): chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" nicklist = ", ".join(sorted(kwargs["nicklist"], key=lambda n: n.lower())) for obj in self._nicklist_callers: - obj.msg(f"Nicks at {chstr}:\n {nicklist}") + obj.msg(_(f"Nicks at {chstr}:\n {nicklist}") self._nicklist_callers = [] return @@ -337,7 +338,7 @@ class IRCBot(Bot): if hasattr(self, "_ping_callers") and self._ping_callers: chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" for obj in self._ping_callers: - obj.msg(f"IRC ping return from {chstr} took {kwargs['timing']}s.") + obj.msg(_(f"IRC ping return from {chstr} took {kwargs['timing']}s.") self._ping_callers = [] return diff --git a/evennia/help/manager.py b/evennia/help/manager.py index 3459efe951..b218eeb9fc 100644 --- a/evennia/help/manager.py +++ b/evennia/help/manager.py @@ -131,7 +131,7 @@ class HelpEntryManager(TypedObjectManager): for topic in topics: topic.help_category = default_category topic.save() - string = "Help database moved to category %s" % default_category + string = _(f"Help database moved to category {default_category}") logger.log_info(string) def search_help(self, ostring, help_category=None): diff --git a/evennia/objects/admin.py b/evennia/objects/admin.py index 49bec928c3..6e765b9523 100644 --- a/evennia/objects/admin.py +++ b/evennia/objects/admin.py @@ -8,7 +8,7 @@ from django.contrib import admin from evennia.typeclasses.admin import AttributeInline, TagInline from evennia.objects.models import ObjectDB from django.contrib.admin.utils import flatten_fieldsets - +from django.utils.translation import gettext as _ class ObjectAttributeInline(AttributeInline): """ @@ -61,7 +61,7 @@ class ObjectCreateForm(forms.ModelForm): required=False, widget=forms.TextInput(attrs={"size": "78"}), help_text="Most non-character objects don't need a cmdset" - " and can leave this field blank.", + " and can leave this field blank.") ) raw_id_fields = ("db_destination", "db_location", "db_home") diff --git a/evennia/utils/validatorfuncs.py b/evennia/utils/validatorfuncs.py index bca25874cb..d368cc4ddd 100644 --- a/evennia/utils/validatorfuncs.py +++ b/evennia/utils/validatorfuncs.py @@ -15,6 +15,7 @@ from django.core.exceptions import ValidationError as _error from django.core.validators import validate_email as _val_email from evennia.utils.ansi import strip_ansi from evennia.utils.utils import string_partial_matching as _partial +from django.utils.translation import gettext as _ _TZ_DICT = {str(tz): _pytz.timezone(tz) for tz in _pytz.common_timezones} @@ -58,7 +59,7 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs) """ if not entry: - raise ValueError(f"No {option_key} entered!") + raise ValueError(_(f"No {option_key} entered!")) if not from_tz: from_tz = _pytz.UTC if account: @@ -66,7 +67,7 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs) try: from_tz = _pytz.timezone(acct_tz) except Exception as err: - raise ValueError(f"Timezone string '{acct_tz}' is not a valid timezone ({err})") + raise ValueError(_(f"Timezone string '{acct_tz}' is not a valid timezone ({err})")) else: from_tz = _pytz.UTC From b6d5b937b5217cfffaa58e378f8bfbc25f30227e Mon Sep 17 00:00:00 2001 From: trhr Date: Wed, 15 Apr 2020 21:58:28 -0500 Subject: [PATCH 2/6] i18n --- evennia/accounts/accounts.py | 4 ++-- evennia/accounts/bots.py | 2 +- evennia/objects/admin.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 24c551fdbb..b361f4f910 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -275,11 +275,11 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): raise RuntimeError("Session not found") if self.get_puppet(session) == obj: # already puppeting this object - self.msg(_("You are already puppeting this object.") + self.msg(_("You are already puppeting this object.")) return if not obj.access(self, "puppet"): # no access - self.msg(_(f"You don't have permission to puppet '{obj.key}'.") + self.msg(_(f"You don't have permission to puppet '{obj.key}'.")) return if obj.account: # object already puppeted diff --git a/evennia/accounts/bots.py b/evennia/accounts/bots.py index 1c1fc7d300..b9ce7f7062 100644 --- a/evennia/accounts/bots.py +++ b/evennia/accounts/bots.py @@ -338,7 +338,7 @@ class IRCBot(Bot): if hasattr(self, "_ping_callers") and self._ping_callers: chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" for obj in self._ping_callers: - obj.msg(_(f"IRC ping return from {chstr} took {kwargs['timing']}s.") + obj.msg(_(f"IRC ping return from {chstr} took {kwargs['timing']}s.")) self._ping_callers = [] return diff --git a/evennia/objects/admin.py b/evennia/objects/admin.py index 6e765b9523..5e18e8e0a4 100644 --- a/evennia/objects/admin.py +++ b/evennia/objects/admin.py @@ -61,7 +61,7 @@ class ObjectCreateForm(forms.ModelForm): required=False, widget=forms.TextInput(attrs={"size": "78"}), help_text="Most non-character objects don't need a cmdset" - " and can leave this field blank.") + " and can leave this field blank." ) raw_id_fields = ("db_destination", "db_location", "db_home") From e0c868fc53128b9c63a12ad4d77884b7e16d63ce Mon Sep 17 00:00:00 2001 From: trhr Date: Wed, 15 Apr 2020 21:59:09 -0500 Subject: [PATCH 3/6] i18n --- evennia/accounts/bots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evennia/accounts/bots.py b/evennia/accounts/bots.py index b9ce7f7062..db68fa09f6 100644 --- a/evennia/accounts/bots.py +++ b/evennia/accounts/bots.py @@ -329,7 +329,7 @@ class IRCBot(Bot): chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" nicklist = ", ".join(sorted(kwargs["nicklist"], key=lambda n: n.lower())) for obj in self._nicklist_callers: - obj.msg(_(f"Nicks at {chstr}:\n {nicklist}") + obj.msg(_(f"Nicks at {chstr}:\n {nicklist}")) self._nicklist_callers = [] return From 5c51bb7e978cd3b3208b652e22456f84159490a2 Mon Sep 17 00:00:00 2001 From: trhr Date: Thu, 16 Apr 2020 05:53:51 -0500 Subject: [PATCH 4/6] fixing fstring --- evennia/accounts/accounts.py | 10 +++++----- evennia/accounts/bots.py | 4 ++-- evennia/commands/cmdhandler.py | 6 ++---- evennia/commands/cmdsethandler.py | 4 ++-- evennia/help/manager.py | 2 +- evennia/locks/lockhandler.py | 2 +- evennia/objects/objects.py | 2 +- evennia/utils/utils.py | 2 +- evennia/utils/validatorfuncs.py | 4 ++-- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index b361f4f910..1f41b577da 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -279,7 +279,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): return if not obj.access(self, "puppet"): # no access - self.msg(_(f"You don't have permission to puppet '{obj.key}'.")) + self.msg(_("You don't have permission to puppet '{key}'.".format(key=obj.key))) return if obj.account: # object already puppeted @@ -300,7 +300,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): self.unpuppet_object(obj.sessions.get()) elif obj.account.is_connected: # controlled by another account - self.msg(_(f"|c{obj.key}|R is already puppeted by another Account.")) + self.msg(_("|c{key}|R is already puppeted by another Account.".format(key=obj.key))) return # do the puppeting @@ -1305,7 +1305,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): """ reason = f" ({reason if reason else ''})" - self._send_to_connect_channel(_(f"|R{self.key} disconnected{reason}|n")) + self._send_to_connect_channel(_("|R{key} disconnected{reason}|n".format(key=self.key))) def at_post_disconnect(self, **kwargs): """ @@ -1411,7 +1411,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if hasattr(target, "return_appearance"): return target.return_appearance(self) else: - return _(f"{target} has no in-game appearance.") + return _("{target} has no in-game appearance.".format(target=target)) else: # list of targets - make list to disconnect from db characters = list(tar for tar in target if tar) if target else [] @@ -1589,7 +1589,7 @@ class DefaultGuest(DefaultAccount): overriding the call (unused by default). """ - self._send_to_connect_channel(_(f"|G{self.key} connected|n")) + self._send_to_connect_channel(_("|G{key} connected|n".format(key=self.key))) self.puppet_object(session, self.db._last_puppet) def at_server_shutdown(self): diff --git a/evennia/accounts/bots.py b/evennia/accounts/bots.py index db68fa09f6..270addac73 100644 --- a/evennia/accounts/bots.py +++ b/evennia/accounts/bots.py @@ -329,7 +329,7 @@ class IRCBot(Bot): chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" nicklist = ", ".join(sorted(kwargs["nicklist"], key=lambda n: n.lower())) for obj in self._nicklist_callers: - obj.msg(_(f"Nicks at {chstr}:\n {nicklist}")) + obj.msg(_("Nicks at {chstr}:\n {nicklist}".format(chstr=chstr, nicklist=nicklist))) self._nicklist_callers = [] return @@ -338,7 +338,7 @@ class IRCBot(Bot): if hasattr(self, "_ping_callers") and self._ping_callers: chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" for obj in self._ping_callers: - obj.msg(_(f"IRC ping return from {chstr} took {kwargs['timing']}s.")) + obj.msg(_("IRC ping return from {chstr} took {time}s.".format(chstr=chstr, time=kwargs['timing']))) self._ping_callers = [] return diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 6f8f247a72..7898b9aedd 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -743,7 +743,7 @@ def cmdhandler( sysarg = raw_string else: # fallback to default error text - sysarg = _("Command '%s' is not available.") % raw_string + sysarg = _("Command '{command}' is not available.".format(command=raw_string)) suggestions = string_suggestions( raw_string, cmdset.get_all_cmd_keys_and_aliases(caller), @@ -751,9 +751,7 @@ def cmdhandler( maxnum=3, ) if suggestions: - sysarg += _(" Maybe you meant %s?") % utils.list_to_string( - suggestions, _("or"), addquote=True - ) + sysarg += _(" Maybe you meant {command}?".format(command=utils.list_to_string(suggestions, _("or"), addquote=True))) else: sysarg += _(' Type "help" for help.') raise ExecSystemCommand(syscmd, sysarg) diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index 395c9c2ba3..4b596e6a50 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -184,7 +184,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False): raise exc.with_traceback(tb) else: # try next suggested path - errstring += _("\n(Unsuccessfully tried '%s')." % python_path) + errstring += _("\n(Unsuccessfully tried '{path}').".format(path=python_path)) continue try: cmdsetclass = getattr(module, classname) @@ -194,7 +194,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False): dum, dum, tb = sys.exc_info() raise exc.with_traceback(tb) else: - errstring += _("\n(Unsuccessfully tried '%s')." % python_path) + errstring += _("\n(Unsuccessfully tried '{path}').".format(path=python_path)) continue _CACHED_CMDSETS[python_path] = cmdsetclass diff --git a/evennia/help/manager.py b/evennia/help/manager.py index b218eeb9fc..02ce32c927 100644 --- a/evennia/help/manager.py +++ b/evennia/help/manager.py @@ -131,7 +131,7 @@ class HelpEntryManager(TypedObjectManager): for topic in topics: topic.help_category = default_category topic.save() - string = _(f"Help database moved to category {default_category}") + string = _("Help database moved to category {default_category}".format(default_category=default_category)) logger.log_info(string) def search_help(self, ostring, help_category=None): diff --git a/evennia/locks/lockhandler.py b/evennia/locks/lockhandler.py index ac8c85abc8..a1b935ddd1 100644 --- a/evennia/locks/lockhandler.py +++ b/evennia/locks/lockhandler.py @@ -246,7 +246,7 @@ class LockHandler(object): evalstring = " ".join(_RE_OK.findall(evalstring)) eval(evalstring % tuple(True for func in funclist), {}, {}) except Exception: - elist.append(_("Lock: definition '%s' has syntax errors.") % raw_lockstring) + elist.append(_("Lock: definition '{lock_string}' has syntax errors.".format(lock_string=raw_lockstring))) continue if access_type in locks: duplicates += 1 diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index de9d09abae..f977996fa1 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -1055,7 +1055,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): # See if we need to kick the account off. for session in self.sessions.all(): - session.msg(_("Your character %s has been destroyed.") % self.key) + session.msg(_("Your character {key} has been destroyed.".format(key=self.key))) # no need to disconnect, Account just jumps to OOC mode. # sever the connection (important!) if self.account: diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index cc191fdd53..ac32801899 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -1916,7 +1916,7 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs): if multimatch_string: error = "%s\n" % multimatch_string else: - error = _("More than one match for '%s' (please narrow target):\n" % query) + error = _("More than one match for '{query}' (please narrow target):\n".format(query=query)) for num, result in enumerate(matches): # we need to consider Commands, where .aliases is a list diff --git a/evennia/utils/validatorfuncs.py b/evennia/utils/validatorfuncs.py index d368cc4ddd..7e4f05cf69 100644 --- a/evennia/utils/validatorfuncs.py +++ b/evennia/utils/validatorfuncs.py @@ -59,7 +59,7 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs) """ if not entry: - raise ValueError(_(f"No {option_key} entered!")) + raise ValueError(_("No {option_key} entered!".format(option_key=option_key))) if not from_tz: from_tz = _pytz.UTC if account: @@ -67,7 +67,7 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs) try: from_tz = _pytz.timezone(acct_tz) except Exception as err: - raise ValueError(_(f"Timezone string '{acct_tz}' is not a valid timezone ({err})")) + raise ValueError(_("Timezone string '{acct_tz}' is not a valid timezone ({err})".format(acct_tz=acct_tz, err=err))) else: from_tz = _pytz.UTC From 220fb47e890f51e703dd2f8de16b238c50d22cff Mon Sep 17 00:00:00 2001 From: trhr Date: Thu, 16 Apr 2020 05:57:51 -0500 Subject: [PATCH 5/6] fixing fstring --- evennia/accounts/accounts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 1f41b577da..1a7260d947 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -1253,7 +1253,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if session: session.msg(logged_in={}) - self._send_to_connect_channel(f"|G{self.key} connected|n") + self._send_to_connect_channel(_("|G{key} connected|n".format(key=self.key))) if _MULTISESSION_MODE == 0: # in this mode we should have only one character available. We # try to auto-connect to our last conneted object, if any @@ -1305,7 +1305,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): """ reason = f" ({reason if reason else ''})" - self._send_to_connect_channel(_("|R{key} disconnected{reason}|n".format(key=self.key))) + self._send_to_connect_channel(_("|R{key} disconnected{reason}|n".format(key=self.key, reason=reason))) def at_post_disconnect(self, **kwargs): """ From 5af43fbee696340971fb97f26cbfb921a3b35717 Mon Sep 17 00:00:00 2001 From: trhr Date: Thu, 16 Apr 2020 06:14:03 -0500 Subject: [PATCH 6/6] fixing fstring --- evennia/accounts/accounts.py | 12 ++++++------ evennia/accounts/bots.py | 4 ++-- evennia/commands/cmdhandler.py | 4 ++-- evennia/commands/cmdsethandler.py | 4 ++-- evennia/help/manager.py | 2 +- evennia/locks/lockhandler.py | 2 +- evennia/objects/objects.py | 2 +- evennia/utils/utils.py | 2 +- evennia/utils/validatorfuncs.py | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 1a7260d947..8986d18473 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -279,7 +279,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): return if not obj.access(self, "puppet"): # no access - self.msg(_("You don't have permission to puppet '{key}'.".format(key=obj.key))) + self.msg(_("You don't have permission to puppet '{key}'.").format(key=obj.key)) return if obj.account: # object already puppeted @@ -300,7 +300,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): self.unpuppet_object(obj.sessions.get()) elif obj.account.is_connected: # controlled by another account - self.msg(_("|c{key}|R is already puppeted by another Account.".format(key=obj.key))) + self.msg(_("|c{key}|R is already puppeted by another Account.").format(key=obj.key)) return # do the puppeting @@ -1253,7 +1253,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if session: session.msg(logged_in={}) - self._send_to_connect_channel(_("|G{key} connected|n".format(key=self.key))) + self._send_to_connect_channel(_("|G{key} connected|n").format(key=self.key)) if _MULTISESSION_MODE == 0: # in this mode we should have only one character available. We # try to auto-connect to our last conneted object, if any @@ -1305,7 +1305,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): """ reason = f" ({reason if reason else ''})" - self._send_to_connect_channel(_("|R{key} disconnected{reason}|n".format(key=self.key, reason=reason))) + self._send_to_connect_channel(_("|R{key} disconnected{reason}|n").format(key=self.key, reason=reason)) def at_post_disconnect(self, **kwargs): """ @@ -1411,7 +1411,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): if hasattr(target, "return_appearance"): return target.return_appearance(self) else: - return _("{target} has no in-game appearance.".format(target=target)) + return _("{target} has no in-game appearance.").format(target=target) else: # list of targets - make list to disconnect from db characters = list(tar for tar in target if tar) if target else [] @@ -1589,7 +1589,7 @@ class DefaultGuest(DefaultAccount): overriding the call (unused by default). """ - self._send_to_connect_channel(_("|G{key} connected|n".format(key=self.key))) + self._send_to_connect_channel(_("|G{key} connected|n").format(key=self.key)) self.puppet_object(session, self.db._last_puppet) def at_server_shutdown(self): diff --git a/evennia/accounts/bots.py b/evennia/accounts/bots.py index 270addac73..6c6a40d0db 100644 --- a/evennia/accounts/bots.py +++ b/evennia/accounts/bots.py @@ -329,7 +329,7 @@ class IRCBot(Bot): chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" nicklist = ", ".join(sorted(kwargs["nicklist"], key=lambda n: n.lower())) for obj in self._nicklist_callers: - obj.msg(_("Nicks at {chstr}:\n {nicklist}".format(chstr=chstr, nicklist=nicklist))) + obj.msg(_("Nicks at {chstr}:\n {nicklist}").format(chstr=chstr, nicklist=nicklist)) self._nicklist_callers = [] return @@ -338,7 +338,7 @@ class IRCBot(Bot): if hasattr(self, "_ping_callers") and self._ping_callers: chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" for obj in self._ping_callers: - obj.msg(_("IRC ping return from {chstr} took {time}s.".format(chstr=chstr, time=kwargs['timing']))) + obj.msg(_("IRC ping return from {chstr} took {time}s.").format(chstr=chstr, time=kwargs['timing'])) self._ping_callers = [] return diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 7898b9aedd..a0d9be8842 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -743,7 +743,7 @@ def cmdhandler( sysarg = raw_string else: # fallback to default error text - sysarg = _("Command '{command}' is not available.".format(command=raw_string)) + sysarg = _("Command '{command}' is not available.").format(command=raw_string) suggestions = string_suggestions( raw_string, cmdset.get_all_cmd_keys_and_aliases(caller), @@ -751,7 +751,7 @@ def cmdhandler( maxnum=3, ) if suggestions: - sysarg += _(" Maybe you meant {command}?".format(command=utils.list_to_string(suggestions, _("or"), addquote=True))) + sysarg += _(" Maybe you meant {command}?").format(command=utils.list_to_string(suggestions, _("or"), addquote=True)) else: sysarg += _(' Type "help" for help.') raise ExecSystemCommand(syscmd, sysarg) diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index 4b596e6a50..4a746df33e 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -184,7 +184,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False): raise exc.with_traceback(tb) else: # try next suggested path - errstring += _("\n(Unsuccessfully tried '{path}').".format(path=python_path)) + errstring += _("\n(Unsuccessfully tried '{path}').").format(path=python_path) continue try: cmdsetclass = getattr(module, classname) @@ -194,7 +194,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False): dum, dum, tb = sys.exc_info() raise exc.with_traceback(tb) else: - errstring += _("\n(Unsuccessfully tried '{path}').".format(path=python_path)) + errstring += _("\n(Unsuccessfully tried '{path}').").format(path=python_path) continue _CACHED_CMDSETS[python_path] = cmdsetclass diff --git a/evennia/help/manager.py b/evennia/help/manager.py index 02ce32c927..646758d202 100644 --- a/evennia/help/manager.py +++ b/evennia/help/manager.py @@ -131,7 +131,7 @@ class HelpEntryManager(TypedObjectManager): for topic in topics: topic.help_category = default_category topic.save() - string = _("Help database moved to category {default_category}".format(default_category=default_category)) + string = _("Help database moved to category {default_category}").format(default_category=default_category) logger.log_info(string) def search_help(self, ostring, help_category=None): diff --git a/evennia/locks/lockhandler.py b/evennia/locks/lockhandler.py index a1b935ddd1..0f96b1d6a7 100644 --- a/evennia/locks/lockhandler.py +++ b/evennia/locks/lockhandler.py @@ -246,7 +246,7 @@ class LockHandler(object): evalstring = " ".join(_RE_OK.findall(evalstring)) eval(evalstring % tuple(True for func in funclist), {}, {}) except Exception: - elist.append(_("Lock: definition '{lock_string}' has syntax errors.".format(lock_string=raw_lockstring))) + elist.append(_("Lock: definition '{lock_string}' has syntax errors.").format(lock_string=raw_lockstring)) continue if access_type in locks: duplicates += 1 diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index f977996fa1..211e0f9fc3 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -1055,7 +1055,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): # See if we need to kick the account off. for session in self.sessions.all(): - session.msg(_("Your character {key} has been destroyed.".format(key=self.key))) + session.msg(_("Your character {key} has been destroyed.").format(key=self.key)) # no need to disconnect, Account just jumps to OOC mode. # sever the connection (important!) if self.account: diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index ac32801899..33da9c31cb 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -1916,7 +1916,7 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs): if multimatch_string: error = "%s\n" % multimatch_string else: - error = _("More than one match for '{query}' (please narrow target):\n".format(query=query)) + error = _("More than one match for '{query}' (please narrow target):\n").format(query=query) for num, result in enumerate(matches): # we need to consider Commands, where .aliases is a list diff --git a/evennia/utils/validatorfuncs.py b/evennia/utils/validatorfuncs.py index 7e4f05cf69..e49bb716a8 100644 --- a/evennia/utils/validatorfuncs.py +++ b/evennia/utils/validatorfuncs.py @@ -59,7 +59,7 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs) """ if not entry: - raise ValueError(_("No {option_key} entered!".format(option_key=option_key))) + raise ValueError(_("No {option_key} entered!").format(option_key=option_key)) if not from_tz: from_tz = _pytz.UTC if account: @@ -67,7 +67,7 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs) try: from_tz = _pytz.timezone(acct_tz) except Exception as err: - raise ValueError(_("Timezone string '{acct_tz}' is not a valid timezone ({err})".format(acct_tz=acct_tz, err=err))) + raise ValueError(_("Timezone string '{acct_tz}' is not a valid timezone ({err})").format(acct_tz=acct_tz, err=err)) else: from_tz = _pytz.UTC