Skip to main content

DjangoTranslation

Set up the GNUTranslations context with regard to output charset.

Attributes

AttributeTypeDescription
domainstring = "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

NameTypeDescription
languagestrThe language code for the translation (e.g., 'en', 'fr').
domainstr = NoneThe translation domain, defaults to 'django'.
localedirslist = NoneA 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

NameTypeDescription
othergettext.GNUTranslationsThe other translation object whose catalog and fallbacks should be merged into this instance.

language()

@classmethod
def language() - > string

Return the translation language.

Returns

TypeDescription
stringThe language code associated with this translation instance.

to_language()

@classmethod
def to_language() - > string

Return the translation language name.

Returns

TypeDescription
stringThe 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

NameTypeDescription
msgid1stringThe singular version of the message ID.
msgid2stringThe plural version of the message ID.
nintThe number used to determine which plural form to use.

Returns

TypeDescription
stringThe translated string corresponding to the plural form of the message.