Support inflection of colored object-names.

Resolves #1572.
This commit is contained in:
Griatch 2018-08-23 18:28:28 +02:00
parent 6ec7c7a63f
commit 247ad0d056

View file

@ -23,6 +23,7 @@ from evennia.commands.cmdsethandler import CmdSetHandler
from evennia.commands import cmdhandler from evennia.commands import cmdhandler
from evennia.utils import search from evennia.utils import search
from evennia.utils import logger from evennia.utils import logger
from evennia.utils import ansi
from evennia.utils.utils import (variable_from_module, lazy_property, from evennia.utils.utils import (variable_from_module, lazy_property,
make_iter, to_unicode, is_iter, list_to_string, make_iter, to_unicode, is_iter, list_to_string,
to_str) to_str)
@ -305,12 +306,13 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
count (int): Number of objects of this type count (int): Number of objects of this type
looker (Object): Onlooker. Not used by default. looker (Object): Onlooker. Not used by default.
Kwargs: Kwargs:
key (str): Optional key to pluralize, use this instead of the object's key. key (str): Optional key to pluralize, if given, use this instead of the object's key.
Returns: Returns:
singular (str): The singular form to display. singular (str): The singular form to display.
plural (str): The determined plural form of the key, including the count. plural (str): The determined plural form of the key, including the count.
""" """
key = kwargs.get("key", self.key) key = kwargs.get("key", self.key)
key = ansi.ANSIString(key) # this is needed to allow inflection of colored names
plural = _INFLECT.plural(key, 2) plural = _INFLECT.plural(key, 2)
plural = "%s %s" % (_INFLECT.number_to_words(count, threshold=12), plural) plural = "%s %s" % (_INFLECT.number_to_words(count, threshold=12), plural)
singular = _INFLECT.an(key) singular = _INFLECT.an(key)