add internationalization for objects.objects.py

This commit is contained in:
JohniFi 2025-03-28 12:27:04 +01:00
parent f49f80a8f3
commit 6382727a6f

View file

@ -1383,8 +1383,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
if obj.has_account: if obj.has_account:
if home: if home:
string = _( string = _(
"Your current location has ceased to exist," "Your current location has ceased to exist," " moving you to (#{dbid})."
" moving you to (#{dbid})."
) )
obj.msg(string.format(dbid=home.dbid)) obj.msg(string.format(dbid=home.dbid))
else: else:
@ -1794,9 +1793,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
exits = self.filter_visible(self.contents_get(content_type="exit"), looker, **kwargs) exits = self.filter_visible(self.contents_get(content_type="exit"), looker, **kwargs)
exit_names = (exi.get_display_name(looker, **kwargs) for exi in exits) exit_names = (exi.get_display_name(looker, **kwargs) for exi in exits)
exit_names = iter_to_str(_sort_exit_names(exit_names)) exit_names = iter_to_str(_sort_exit_names(exit_names), endsep=_("and"))
e = _("Exits")
return f"|wExits:|n {exit_names}" if exit_names else "" return f"|w{e}:|n {exit_names}" if exit_names else ""
def get_display_characters(self, looker, **kwargs): def get_display_characters(self, looker, **kwargs):
""" """
@ -1813,10 +1812,10 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
self.contents_get(content_type="character"), looker, **kwargs self.contents_get(content_type="character"), looker, **kwargs
) )
character_names = iter_to_str( character_names = iter_to_str(
char.get_display_name(looker, **kwargs) for char in characters (char.get_display_name(looker, **kwargs) for char in characters), endsep=_("and")
) )
c = _("Characters")
return f"|wCharacters:|n {character_names}" if character_names else "" return f"|w{c}:|n {character_names}" if character_names else ""
def get_display_things(self, looker, **kwargs): def get_display_things(self, looker, **kwargs):
""" """
@ -1842,8 +1841,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
thing = thinglist[0] thing = thinglist[0]
singular, plural = thing.get_numbered_name(nthings, looker, key=thingname) singular, plural = thing.get_numbered_name(nthings, looker, key=thingname)
thing_names.append(singular if nthings == 1 else plural) thing_names.append(singular if nthings == 1 else plural)
thing_names = iter_to_str(thing_names) thing_names = iter_to_str(thing_names, endsep=_("and"))
return f"|wYou see:|n {thing_names}" if thing_names else "" s = _("You see")
return f"|w{s}:|n {thing_names}" if thing_names else ""
def get_display_footer(self, looker, **kwargs): def get_display_footer(self, looker, **kwargs):
""" """
@ -2321,7 +2321,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
if msg: if msg:
string = msg string = msg
else: else:
string = "{object} is leaving {origin}, heading for {destination}." string = _("{object} is leaving {origin}, heading for {destination}.")
location = self.location location = self.location
exits = [ exits = [
@ -2333,9 +2333,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
mapping.update( mapping.update(
{ {
"object": self, "object": self,
"exit": exits[0] if exits else "somewhere", "exit": exits[0] if exits else _("somewhere"),
"origin": location or "nowhere", "origin": location or _("nowhere"),
"destination": destination or "nowhere", "destination": destination or _("nowhere"),
} }
) )
@ -2406,9 +2406,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
mapping.update( mapping.update(
{ {
"object": self, "object": self,
"exit": exits[0] if exits else "somewhere", "exit": exits[0] if exits else _("somewhere"),
"origin": origin or "nowhere", "origin": origin or _("nowhere"),
"destination": destination or "nowhere", "destination": destination or _("nowhere"),
} }
) )
@ -2672,9 +2672,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
""" """
if not target.access(self, "view"): if not target.access(self, "view"):
try: try:
return "Could not view '%s'." % target.get_display_name(self, **kwargs) return _("Could not view '{target_name}'.").format(
target_name=target.get_display_name(self, **kwargs)
)
except AttributeError: except AttributeError:
return "Could not view '%s'." % target.key return _("Could not view '{target_name}'.").format(target_name=target.key)
description = target.return_appearance(self, **kwargs) description = target.return_appearance(self, **kwargs)
@ -2911,15 +2913,15 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
# whisper mode # whisper mode
msg_type = "whisper" msg_type = "whisper"
msg_self = ( msg_self = (
'{self} whisper to {all_receivers}, "|n{speech}|n"' _('{self} whisper to {all_receivers}, "|n{speech}|n"')
if msg_self is True if msg_self is True
else msg_self else msg_self
) )
msg_receivers = msg_receivers or '{object} whispers: "|n{speech}|n"' msg_receivers = msg_receivers or _('{object} whispers: "|n{speech}|n"')
msg_location = None msg_location = None
else: else:
msg_self = '{self} say, "|n{speech}|n"' if msg_self is True else msg_self msg_self = _('{self} say, "|n{speech}|n"') if msg_self is True else msg_self
msg_location = msg_location or '{object} says, "{speech}"' msg_location = msg_location or _('{object} says, "{speech}"')
msg_receivers = msg_receivers or message msg_receivers = msg_receivers or message
custom_mapping = kwargs.get("mapping", {}) custom_mapping = kwargs.get("mapping", {})
@ -2928,7 +2930,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
if msg_self: if msg_self:
self_mapping = { self_mapping = {
"self": "You", "self": _("You"),
"object": self.get_display_name(self), "object": self.get_display_name(self),
"location": location.get_display_name(self) if location else None, "location": location.get_display_name(self) if location else None,
"receiver": None, "receiver": None,
@ -2944,7 +2946,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
if receivers and msg_receivers: if receivers and msg_receivers:
receiver_mapping = { receiver_mapping = {
"self": "You", "self": _("You"),
"object": None, "object": None,
"location": None, "location": None,
"receiver": None, "receiver": None,
@ -2971,7 +2973,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
if self.location and msg_location: if self.location and msg_location:
location_mapping = { location_mapping = {
"self": "You", "self": _("You"),
"object": self, "object": self,
"location": location, "location": location,
"all_receivers": ", ".join(str(recv) for recv in receivers) if receivers else None, "all_receivers": ", ".join(str(recv) for recv in receivers) if receivers else None,
@ -3196,7 +3198,7 @@ class DefaultCharacter(DefaultObject):
""" """
if account and cls.objects.filter_family(db_key__iexact=name): if account and cls.objects.filter_family(db_key__iexact=name):
return f"|rA character named '|w{name}|r' already exists.|n" return _("|rA character named '|w{name}|r' already exists.|n").format(name=name)
def basetype_setup(self): def basetype_setup(self):
""" """
@ -3500,7 +3502,9 @@ class ExitCommand(_COMMAND_DEFAULT_CLASS):
""" """
if self.obj.destination: if self.obj.destination:
return " (exit to %s)" % self.obj.destination.get_display_name(caller, **kwargs) return _(" (exit to {destination})").format(
destination=self.obj.destination.get_display_name(caller, **kwargs)
)
else: else:
return " (%s)" % self.obj.get_display_name(caller, **kwargs) return " (%s)" % self.obj.get_display_name(caller, **kwargs)