gettext

internationalization message catalog lookup

TLDR

Display translated string
$ gettext [domain] "[message]"
Translate from catalog
$ TEXTDOMAIN=[domain] gettext "[message]"
With context
$ gettext -c "[context]" "[message]"
Plural forms
$ ngettext "[singular]" "[plural]" [count]

SYNOPSIS

gettext [options] [domain] msgid

DESCRIPTION

gettext retrieves translated strings from message catalogs. It's the runtime component of the GNU internationalization system, looking up translations based on the current locale.The tool searches .mo files for translations, returning the original if none found. It enables shell scripts and programs to produce localized output.gettext enables internationalization of command-line applications.

PARAMETERS

DOMAIN

Message catalog domain.
MSGID
Message to translate.
-d DOMAIN
Text domain.
-e
Enable escape interpretation.
-E
Preserve but don't interpret backslashes.
-c CONTEXT
Message context.
--help
Display help information.

CONFIGURATION

/usr/share/locale/[LANG]/LC_MESSAGES/[domain].mo

Compiled message catalogs containing translations for specific domains and locales.

INSTALL

sudo apt install gettext-base
sudo dnf install gettext
sudo pacman -S gettext
sudo apk add gettext
brew install gettext
nix profile install nixpkgs#gettext

CAVEATS

Requires compiled .mo catalogs. LANG/LC_MESSAGES must be set. Missing translations return original.

HISTORY

gettext was developed by GNU for internationalization. It became the standard Unix localization system, enabling software to support multiple languages.

SEE ALSO

xgettext(1), msgfmt(1), envsubst(1)

RESOURCES

Homepage · Documentation