Lines Matching +full:install +full:- +full:module
1 :mod:`gettext` --- Multilingual internationalization services
4 .. module:: gettext
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
18 to write your module and application messages in one natural language, and
26 --------------------------
28 The :mod:`gettext` module defines the following API, which is very similar to
32 locale of your user. If you are localizing a Python module, or if your
34 class-based API instead.
114 Class-based API
115 ---------------
117 The class-based API of the :mod:`gettext` module gives you more flexibility and
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
178 .. function:: install(domain, localedir=None, *, names=None)
184 object's :meth:`~NullTranslations.install` method.
197 *names* is now a keyword-only parameter.
219 No-op in the base class, this method takes file object *fp*, and reads
272 .. method:: install(names=None)
274 This method installs :meth:`.gettext` into the built-in namespace,
278 names of functions you want to install in the builtins namespace in
284 the entire application globally, and specifically the built-in namespace,
285 localized modules should never install :func:`_`. Instead, they should use
286 this code to make :func:`_` available to their module::
292 This puts :func:`_` only in the module's global namespace and so only
293 affects calls within this module.
302 The :mod:`gettext` module provides one additional class derived from
305 in both big-endian and little-endian format.
309 the translation for the empty string. This metadata is in :rfc:`822`\ -style
310 ``key: value`` pairs, and should contain the ``Project-Id-Version`` key. If the
311 key ``Content-Type`` is found, then the ``charset`` property is used to
342 Do a plural-forms lookup of a message id. *singular* is used as the message id
374 Do a plural-forms lookup of a message id. *singular* is used as the
399 GNOME uses a version of the :mod:`gettext` module by James Henstridge, but this
407 For compatibility with this older module, the function :func:`Catalog` is an
410 One difference between this module and Henstridge's: his catalog objects
416 --------------------------------------------
424 #. prepare your program or module by specially marking translatable strings
428 #. create language-specific translations of the message catalogs
430 #. use the :mod:`gettext` module so that message strings are properly translated
434 it in ``_('...')`` --- that is, a call to the function :func:`_`. For example::
452 his `po-utils package <https://github.com/pinard/po-utils>`__.
454 (Python also includes pure-Python versions of these programs, called
456 will install them for you. :program:`pygettext.py` is similar to
459 :program:`pygettext.py` supports a command-line interface similar to
461 --help``. :program:`msgfmt.py` is binary compatible with GNU
468 human-readable files that contain every marked string in the source
475 language-specific versions as a :file:`<language-name>.po` file that's
476 compiled into a machine-readable :file:`.mo` binary catalog file using
478 :mod:`gettext` module for the actual translation processing at
479 run-time.
481 How you use the :mod:`gettext` module in your code depends on whether you are
482 internationalizing a single module or your entire application. The next two
486 Localizing your module
489 If you are localizing your module, you must take care not to make global
490 changes, e.g. to the built-in namespace. You should not use the GNU :program:`gettext`
491 API but instead the class-based API.
493 Let's say your module is called "spam" and the module's various natural language
496 module::
506 If you are localizing your application, you can install the :func:`_` function
507 globally into the built-in namespace, usually in the main driver file of your
508 application. This will let all your application-specific files just use
509 ``_('...')`` without having to explicitly install it in each file.
515 gettext.install('myapplication')
518 :func:`install` function::
521 gettext.install('myapplication', '/usr/share/locale')
538 lang1.install()
541 lang2.install()
544 lang3.install()
585 of :func:`_` in the built-in namespace (until the :keyword:`del` command). Take
612 support this through the use of the :option:`!-k` command-line switch.
618 ----------------
621 implementations, and valuable experience to the creation of this module:
629 * Marc-André Lemburg
643 The :mod:`gettext` module does not try to support these system dependent