# pydoc > gettext

---
type: CommandReference
command: gettext
mode: pydoc
section: ""
source: pydoc3
---

## Quick Reference

- `gettext.install('domain')` — Install the `_()` function globally.
- `gettext.translation('domain', localedir, languages)` — Return a GNUTranslations object.
- `t.gettext('msg')` — Translate a message.
- `t.ngettext('single', 'plural', n)` — Translate plural forms.
- `t.pgettext(context, msg)` — Context-sensitive translation.
- `gettext.find('domain', localedir, languages)` — Locate a .mo file.
- `gettext.textdomain('domain')` — Set or get the current domain.
- `gettext.bindtextdomain('domain', localedir)` — Bind a domain to a directory.

## Name

gettext — Internationalization and localization support.

## Synopsis

python
import gettext
# Create a translation object
t = gettext.translation('myapp', localedir='/path/to/locale', languages=['en', 'de'])
# Install _() for global use
t.install()
# Translate
print(_('Hello World'))
Or use the low-level API:

python
gettext.bindtextdomain('myapp', '/path/to/locale')
gettext.textdomain('myapp')
print(gettext.gettext('Hello World'))
## Functions

- `gettext(message)` — Return the localized translation of message, based on the current global domain.
- `dgettext(domain, message)` — Like `gettext()`, but look up the message in the specified domain.
- `ngettext(msgid1, msgid2, n)` — Plural version of `gettext()`.
- `dngettext(domain, msgid1, msgid2, n)` — Plural version of `dgettext()`.
- `pgettext(context, message)` — Context-sensitive translation.
- `dpgettext(domain, context, message)` — Context-sensitive with domain.
- `npgettext(context, msgid1, msgid2, n)` — Context-sensitive plural.
- `dnpgettext(domain, context, msgid1, msgid2, n)` — All together.
- `lgettext(message)` — Return the localized translation encoded in the system's preferred encoding.
- `ldgettext(domain, message)` — Like `lgettext()` with domain.
- `lngettext(msgid1, msgid2, n)` — Plural version of `lgettext()`.
- `ldngettext(domain, msgid1, msgid2, n)` — Plural version of `ldgettext()`.
- `bindtextdomain(domain, localedir)` — Bind domain to a locale directory.
- `bind_textdomain_codeset(domain, codeset)` — Set the codeset for a domain.
- `textdomain(domain=None)` — Set or get the current domain.
- `find(domain, localedir=None, languages=None, all=False)` — Locate a .mo file using the gettext strategy.
- `translation(domain, localedir=None, languages=None, class_=None, fallback=False, codeset=None)` — Return a `*Translations` instance based on the domain. (Shorthand: `Catalog = translation`.)
- `install(domain, localedir=None, codeset=None, names=None)` — Install the `_()` function in the builtins namespace.

## Classes

### `NullTranslations([fp])`

Base class for translations. Methods:

- `__init__(self, fp=None)` — Initialize self.
- `add_fallback(self, fallback)` — Add a fallback translation object.
- `charset(self)` — Return the current charset.
- `gettext(self, message)` — Return the translated message.
- `info(self)` — Return the information dictionary from the .mo file.
- `install(self, names=None)` — Install the object's `gettext()` as `_()` in builtins.
- `lgettext(self, message)` — Return the translated message in the system's encoding.
- `lngettext(self, msgid1, msgid2, n)` — Plural version of `lgettext()`.
- `ngettext(self, msgid1, msgid2, n)` — Plural version of `gettext()`.
- `npgettext(self, context, msgid1, msgid2, n)` — Context-sensitive plural.
- `output_charset(self)` — Return the output charset.
- `pgettext(self, context, message)` — Context-sensitive translation.
- `set_output_charset(self, charset)` — Set the output charset.

### `GNUTranslations([fp])`

Subclass of `NullTranslations` implementing GNU gettext format. Additional methods and attributes:

- `gettext(self, message)` — Overridden.
- `lgettext(self, message)` — Overridden.
- `lngettext(self, msgid1, msgid2, n)` — Overridden.
- `ngettext(self, msgid1, msgid2, n)` — Overridden.
- `npgettext(self, context, msgid1, msgid2, n)` — Overridden.
- `pgettext(self, context, message)` — Overridden.
- `BE_MAGIC = 3725722773` — Big-endian magic number.
- `CONTEXT = '%s\x04%s'` — Context separator format.
- `LE_MAGIC = 2500072158` — Little-endian magic number.
- `VERSIONS = (0, 1)` — Supported .mo file versions.

## See Also

- [Python gettext documentation](https://docs.python.org/3.10/library/gettext.html)
- GNU gettext manual