DjangoTranslation
Set up the GNUTranslations context with regard to output charset.
Attributes
| Attribute | Type | Description |
|---|---|---|
| domain | string = "django" | The gettext message domain used to locate and merge translation catalogs, defaulting to 'django'. |
Constructor
Signature
def DjangoTranslation(
language: str,
domain: str = None,
localedirs: list = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| language | str | The language code for the translation (e.g., 'en', 'fr'). |
| domain | str = None | The translation domain, defaults to 'django'. |
| localedirs | list = None | A list of paths to locale directories to search for translations. |
Methods
merge()
@classmethod
def merge(
other: gettext.GNUTranslations
)
Merge another translation into this catalog.
Parameters
| Name | Type | Description |
|---|---|---|
| other | gettext.GNUTranslations | The other translation object whose catalog and fallbacks should be merged into this instance. |
language()
@classmethod
def language() - > string
Return the translation language.
Returns
| Type | Description |
|---|---|
string | The language code associated with this translation instance. |
to_language()
@classmethod
def to_language() - > string
Return the translation language name.
Returns
| Type | Description |
|---|---|
string | The normalized language name string. |
ngettext()
@classmethod
def ngettext(
msgid1: string,
msgid2: string,
n: int
) - > string
Fetches the plural form of a translation based on the provided count. It checks the local catalog before falling back to the default language or returning the original message IDs.
Parameters
| Name | Type | Description |
|---|---|---|
| msgid1 | string | The singular version of the message ID. |
| msgid2 | string | The plural version of the message ID. |
| n | int | The number used to determine which plural form to use. |
Returns
| Type | Description |
|---|---|
string | The translated string corresponding to the plural form of the message. |