Internationalization for comms and objects.

This commit is contained in:
Kai Huang 2016-02-07 07:48:33 -06:00 committed by Griatch
parent e80ad9fd18
commit fd2f762730
2 changed files with 26 additions and 23 deletions

View file

@ -65,19 +65,19 @@ class ChannelCommand(command.Command):
channelkey, msg = self.args channelkey, msg = self.args
caller = self.caller caller = self.caller
if not msg: if not msg:
self.msg("Say what?") self.msg(_("Say what?"))
return return
channel = ChannelDB.objects.get_channel(channelkey) channel = ChannelDB.objects.get_channel(channelkey)
if not channel: if not channel:
self.msg("Channel '%s' not found." % channelkey) self.msg(_("Channel '%s' not found.") % channelkey)
return return
if not channel.has_connection(caller): if not channel.has_connection(caller):
string = "You are not connected to channel '%s'." string = _("You are not connected to channel '%s'.")
self.msg(string % channelkey) self.msg(string % channelkey)
return return
if not channel.access(caller, 'send'): if not channel.access(caller, 'send'):
string = "You are not permitted to send to channel '%s'." string = _("You are not permitted to send to channel '%s'.")
self.msg(string % channelkey) self.msg(string % channelkey)
return return
channel.msg(msg, senders=self.caller, online=True) channel.msg(msg, senders=self.caller, online=True)
@ -142,9 +142,9 @@ class ChannelHandler(object):
key = channel.key key = channel.key
aliases = channel.aliases.all() aliases = channel.aliases.all()
ustring = "%s <message>" % key.lower() + "".join(["\n %s <message>" % alias.lower() for alias in aliases]) ustring = _("%s <message>") % key.lower() + "".join([_("\n %s <message>") % alias.lower() for alias in aliases])
desc = channel.db.desc desc = channel.db.desc
string = \ string = _(
""" """
Channel '%s' Channel '%s'
@ -152,7 +152,7 @@ class ChannelHandler(object):
%s %s
%s %s
""" % (key, ustring, desc) """) % (key, ustring, desc)
return string return string
def add_channel(self, channel): def add_channel(self, channel):

View file

@ -9,6 +9,7 @@ from builtins import object
from future.utils import listvalues, with_metaclass from future.utils import listvalues, with_metaclass
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext as _
from evennia.typeclasses.models import TypeclassBase from evennia.typeclasses.models import TypeclassBase
from evennia.typeclasses.attributes import NickHandler from evennia.typeclasses.attributes import NickHandler
@ -1097,8 +1098,9 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
loc_name = "" loc_name = ""
loc_name = self.location.name loc_name = self.location.name
dest_name = destination.name dest_name = destination.name
string = "%s is leaving %s, heading for %s." string = _("{name} is leaving {loc_name}, heading for {dest_name}.").format(
self.location.msg_contents(string % (name, loc_name, dest_name), exclude=self) name=name, loc_name=loc_name, dest_name=dest_name)
self.location.msg_contents(string, exclude=self)
def announce_move_to(self, source_location): def announce_move_to(self, source_location):
""" """
@ -1114,7 +1116,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
if not source_location and self.location.has_player: if not source_location and self.location.has_player:
# This was created from nowhere and added to a player's # This was created from nowhere and added to a player's
# inventory; it's probably the result of a create command. # inventory; it's probably the result of a create command.
string = "You now have %s in your possession." % name string = _("You now have %s in your possession.") % name
self.location.msg(string) self.location.msg(string)
return return
@ -1122,8 +1124,9 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
loc_name = self.location.name loc_name = self.location.name
if source_location: if source_location:
src_name = source_location.name src_name = source_location.name
string = "%s arrives to %s from %s." string = _("{name} arrives to {loc_name} from {src_name}.").format(
self.location.msg_contents(string % (name, loc_name, src_name), exclude=self) name=name, loc_name=loc_name, src_name=src_name)
self.location.msg_contents(string, exclude=self)
def at_after_move(self, source_location): def at_after_move(self, source_location):
""" """
@ -1281,14 +1284,14 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
else: else:
things.append(key) things.append(key)
# get description, build string # get description, build string
string = "{c%s{n\n" % self.get_display_name(looker) string = _("{c%s{n\n" % self.get_display_name(looker))
desc = self.db.desc desc = self.db.desc
if desc: if desc:
string += "%s" % desc string += "%s" % desc
if exits: if exits:
string += "\n{wExits:{n " + ", ".join(exits) string += _("\n{wExits:{n " + ", ".join(exits))
if users or things: if users or things:
string += "\n{wYou see:{n " + ", ".join(users + things) string += _("\n{wYou see:{n " + ", ".join(users + things))
return string return string
def at_look(self, target): def at_look(self, target):
@ -1308,7 +1311,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
""" """
if not target.access(self, "view"): if not target.access(self, "view"):
return "Could not find '%s'." % target return _("Could not find '%s'.") % target
# the target's at_desc() method. # the target's at_desc() method.
target.at_desc(looker=self) target.at_desc(looker=self)
return target.return_appearance(self) return target.return_appearance(self)
@ -1427,7 +1430,7 @@ class DefaultCharacter(DefaultObject):
self.db.prelogout_location = self.location self.db.prelogout_location = self.location
self.location.at_object_receive(self, self.location) self.location.at_object_receive(self, self.location)
else: else:
player.msg("{r%s has no location and no home is set.{n" % self, session=session) player.msg(_("{r%s has no location and no home is set.{n") % self, session=session)
def at_post_puppet(self): def at_post_puppet(self):
""" """
@ -1435,11 +1438,11 @@ class DefaultCharacter(DefaultObject):
Player<->Object links have been established. Player<->Object links have been established.
""" """
self.msg("\nYou become {c%s{n.\n" % self.name) self.msg(_("\nYou become {c%s{n.\n") % self.name)
self.msg(self.at_look(self.location)) self.msg(self.at_look(self.location))
def message(obj, from_obj): def message(obj, from_obj):
obj.msg("%s has entered the game." % self.get_display_name(obj), from_obj=from_obj) obj.msg(_("%s has entered the game.") % self.get_display_name(obj), from_obj=from_obj)
self.location.for_contents(message, exclude=[self], from_obj=self) self.location.for_contents(message, exclude=[self], from_obj=self)
def at_post_unpuppet(self, player, session=None): def at_post_unpuppet(self, player, session=None):
@ -1458,7 +1461,7 @@ class DefaultCharacter(DefaultObject):
# only remove this char from grid if no sessions control it anymore. # only remove this char from grid if no sessions control it anymore.
if self.location: if self.location:
def message(obj, from_obj): def message(obj, from_obj):
obj.msg("%s has left the game." % self.get_display_name(obj), from_obj=from_obj) obj.msg(_("%s has left the game.") % self.get_display_name(obj), from_obj=from_obj)
self.location.for_contents(message, exclude=[self], from_obj=self) self.location.for_contents(message, exclude=[self], from_obj=self)
self.db.prelogout_location = self.location self.db.prelogout_location = self.location
self.location = None self.location = None
@ -1525,9 +1528,9 @@ class ExitCommand(command.Command):
A string with identifying information to disambiguate the command, conventionally with a preceding space. A string with identifying information to disambiguate the command, conventionally with a preceding space.
""" """
if self.obj.destination: if self.obj.destination:
return " (exit to %s)" % self.obj.destination.get_display_name(caller) return _(" (exit to %s)") % self.obj.destination.get_display_name(caller)
else: else:
return " (%s)" % self.obj.get_display_name(caller) return _(" (%s)") % self.obj.get_display_name(caller)
# #
# Base Exit object # Base Exit object
@ -1664,4 +1667,4 @@ class DefaultExit(DefaultObject):
read for an error string instead. read for an error string instead.
""" """
traversing_object.msg("You cannot go there.") traversing_object.msg(_("You cannot go there."))