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