"""
Pluralization and singularization helpers for English words.
This module provides thin wrappers around the underlying inflection utilities
for converting words between singular and plural forms. It also exposes a
helper for formatting a word with its count using grammatically correct forms.
The module contains the following public components:
* :func:`plural_form` - Convert a word to its plural form.
* :func:`singular_form` - Convert a word to its singular form.
* :func:`plural_word` - Format a word with its count using correct plurality.
Example::
>>> from hbutils.string.plural import plural_form, singular_form, plural_word
>>> plural_form('woman')
'women'
>>> singular_form('women')
'woman'
>>> plural_word(3, 'word')
'3 words'
.. note::
These helpers delegate to :func:`hbutils.string.inflection.pluralize` and
:func:`hbutils.string.inflection.singularize`, which implement both regular
and irregular English inflection rules.
"""
from .inflection import pluralize, singularize
__all__ = [
'plural_form', 'plural_word', 'singular_form'
]
[docs]
def plural_word(count: int, word: str) -> str:
"""
Format a word with its count using correct plurality.
If ``count`` is 1, the singular form is used; otherwise, the plural form is
used. The singular form is derived from :func:`singular_form` and the
plural form from :func:`plural_form`, which handle irregular inflections.
:param count: Count of the word.
:type count: int
:param word: Word to be pluralized.
:type word: str
:return: Formatted string with the count and correct word form.
:rtype: str
Example::
>>> from hbutils.string import plural_word
>>> plural_word(0, 'word')
'0 words'
>>> plural_word(1, 'word')
'1 word'
>>> plural_word(2, 'word')
'2 words'
>>> plural_word(20, 'word')
'20 words'
>>> plural_word(233, 'word')
'233 words'
"""
single_word = singular_form(word)
if count != 1:
return f'{count} {plural_form(single_word)}'
else:
return f'{count} {single_word}'