Pluralization
Pluralization is powered by Babel and follows CLDR Plural Rules.
To use it:
- Define the required forms (e.g.,
one,few,many,other) in your localization file. - Call the key as a function in Python, passing
countas the first positional argument.
doti18n automatically selects the correct form based on the locale and the count.
Basic Example#
Usage:
from doti18n import LocaleData
i18n = LocaleData("locales")
print(i18n["en"].cat(1)) # Output: 1 cat
print(i18n["en"].cat(3)) # Output: 3 cats
print(i18n["en"].cat(11)) # Output: 11 cats
With Variables#
You can mix pluralization with variable interpolation. Use standard Python formatting {variable} inside the strings and pass values as keyword arguments.
locales/en.xml:
Usage: