Lines Matching +full:- +full:gettext
1 :mod:`!gettext` --- Multilingual internationalization services
4 .. module:: gettext
10 **Source code:** :source:`Lib/gettext.py`
12 --------------
14 The :mod:`gettext` module provides internationalization (I18N) and localization
16 GNU :program:`gettext` message catalog API and a higher level, class-based API that may
25 GNU :program:`gettext` API
26 --------------------------
28 The :mod:`gettext` module defines the following API, which is very similar to
29 the GNU :program:`gettext` API. If you use this API you will affect the
34 class-based API instead.
40 :mod:`gettext` will look for binary :file:`.mo` files for the given domain using
56 .. index:: single: _ (underscore); gettext
57 .. function:: gettext(message)
66 Like :func:`.gettext`, but look the message up in the specified *domain*.
71 Like :func:`.gettext`, but consider plural forms. If a translation is found,
79 `the GNU gettext documentation <https://www.gnu.org/software/gettext/manual/gettext.html>`__
95 is, :func:`gettext`, :func:`dgettext`, :func:`ngettext`, :func:`dngettext`),
101 Note that GNU :program:`gettext` also defines a :func:`!dcgettext` method, but
106 import gettext
107 gettext.bindtextdomain('myapplication', '/path/to/my/language/directory')
108 gettext.textdomain('myapplication')
109 _ = gettext.gettext
114 Class-based API
115 ---------------
117 The class-based API of the :mod:`gettext` module gives you more flexibility and
118 greater convenience than the GNU :program:`gettext` API. It is the recommended
119 way of localizing your Python applications and modules. :mod:`!gettext` defines
122 install themselves in the built-in namespace as the function :func:`!_`.
135 :envvar:`LANG`. The first one returning a non-empty value is used for the
194 *names* is now a keyword-only parameter.
216 No-op in the base class, this method takes file object *fp*, and reads
229 .. method:: gettext(message)
231 If a fallback has been set, forward :meth:`!gettext` to the fallback.
271 This method installs :meth:`.gettext` into the built-in namespace,
276 addition to :func:`!_`. Supported names are ``'gettext'``, ``'ngettext'``,
281 the entire application globally, and specifically the built-in namespace,
285 import gettext
286 t = gettext.translation('mymodule', ...)
287 _ = t.gettext
299 The :mod:`!gettext` module provides one additional class derived from
301 :meth:`!_parse` to enable reading GNU :program:`gettext` format :file:`.mo` files
302 in both big-endian and little-endian format.
305 catalog. It is convention with GNU :program:`gettext` to include metadata as
306 the translation for the empty string. This metadata is in :rfc:`822`\ -style
307 ``key: value`` pairs, and should contain the ``Project-Id-Version`` key. If the
308 key ``Content-Type`` is found, then the ``charset`` property is used to
314 Since message ids are read as Unicode strings too, all ``*gettext()`` methods
328 .. method:: gettext(message)
333 fallback's :meth:`~NullTranslations.gettext` method. Otherwise, the
339 Do a plural-forms lookup of a message id. *singular* is used as the message id
371 Do a plural-forms lookup of a message id. *singular* is used as the
396 GNOME uses a version of the :mod:`gettext` module by James Henstridge, but this
399 import gettext
400 cat = gettext.Catalog(domain, localedir)
401 _ = cat.gettext
411 .. _i18n-howto:
414 --------------------------------------------
426 #. create language-specific translations of the message catalogs
428 #. use the :mod:`gettext` module so that message strings are properly translated
432 it in ``_('...')`` --- that is, a call to the function :func:`_ <gettext>`. For example::
443 The original GNU :program:`gettext` only supported C or C++ source
450 his `po-utils package <https://github.com/pinard/po-utils>`__.
452 (Python also includes pure-Python versions of these programs, called
457 :program:`pygettext.py` supports a command-line interface similar to
459 --help``. :program:`msgfmt.py` is binary compatible with GNU
461 :program:`gettext` package to internationalize your Python
466 human-readable files that contain every marked string in the source
473 language-specific versions as a :file:`<language-name>.po` file that's
474 compiled into a machine-readable :file:`.mo` binary catalog file using
476 :mod:`gettext` module for the actual translation processing at
477 run-time.
479 How you use the :mod:`gettext` module in your code depends on whether you are
488 changes, e.g. to the built-in namespace. You should not use the GNU :program:`gettext`
489 API but instead the class-based API.
493 :program:`gettext` format. Here's what you would put at the top of your
496 import gettext
497 t = gettext.translation('spam', '/usr/share/locale')
498 _ = t.gettext
505 globally into the built-in namespace, usually in the main driver file of your
506 application. This will let all your application-specific files just use
512 import gettext
513 gettext.install('myapplication')
518 import gettext
519 gettext.install('myapplication', '/usr/share/locale')
529 import gettext
531 lang1 = gettext.translation('myapplication', languages=['en'])
532 lang2 = gettext.translation('myapplication', languages=['fr'])
533 lang3 = gettext.translation('myapplication', languages=['de'])
583 of :func:`!_` in the built-in namespace (until the :keyword:`del` command). Take
588 translatable to the :program:`gettext` program, because the parameter
610 support this through the use of the :option:`!-k` command-line switch.
616 ----------------
627 * Marc-André Lemburg
641 The :mod:`!gettext` module does not try to support these system dependent