Merge pull request #3466 from chiizujin/proper_names

Add support to get_numbered_name() for omitting the article
This commit is contained in:
Griatch 2024-04-01 14:53:31 +02:00 committed by GitHub
commit 99d217e0be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View file

@ -1476,14 +1476,19 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
method is used.
return_string (bool): If `True`, return only the singular form if count is 0,1 or
the plural form otherwise. If `False` (default), return both forms as a tuple.
no_article (bool): If `True`, do not return an article if `count` is 1.
Returns:
tuple: This is a tuple `(str, str)` with the singular and plural forms of the key
including the count.
Examples:
::
obj.get_numbered_name(3, looker, key="foo") -> ("a foo", "three foos")
::
- obj.get_numbered_name(3, looker, key="foo") -> ("a foo", "three foos")
- obj.get_numbered_name(1, looker, key="Foobert", return_string=True)
-> "a Foobert"
- obj.get_numbered_name(1, looker, key="Foobert", return_string=True, no_article=True)
-> "Foobert"
"""
plural_category = "plural_key"
@ -1505,6 +1510,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
# look at 'an egg'.
self.aliases.add(singular, category=plural_category)
if kwargs.get("no_article") and count == 1:
if kwargs.get("return_string"):
return key
return key, key
if kwargs.get("return_string"):
return singular if count==1 else plural

View file

@ -185,6 +185,11 @@ class DefaultObjectTest(BaseEvenniaTest):
pattern,
)
def test_get_name_without_article(self):
self.assertEqual(self.obj1.get_numbered_name(1, self.char1, return_string=True), "an Obj")
self.assertEqual(
self.obj1.get_numbered_name(1, self.char1, return_string=True, no_article=True), "Obj"
)
class TestObjectManager(BaseEvenniaTest):
"Test object manager methods"