all Python 3gettextfunction
gettext.install()
translation catalogs
Loads a domain's catalog and puts the _() function into builtins so strings can be translated in any module without an import.
Syntax
gettext.install(domain, localedir=None, *, names=None)
install enables fallback itself: if no catalog is found, _() just returns the original string without an error. It changes builtins for the whole program, so it suits an application but not a library, which would overwrite the host's _. Another trap: the interactive shell also stores the last result in _ and clobbers the function.
Examples
import builtins, gettext
gettext.install('app', 'loc')
print(builtins._('Hello')) # → Hello — каталога нет, строка как есть
gettext.install('app', 'loc', names=['ngettext'])
print(builtins.ngettext('file', 'files', 2)) # → files
See also
Open in the full glossarydocs.python.orgReport an inaccuracy