Debian Codegraph @

docs/support.rst

raw
1 .. -*- mode: rst; encoding: utf-8 -*-
2
3 =============================
4 Support Classes and Functions
5 =============================
6
7 The ``babel.support`` modules contains a number of classes and functions that
8 can help with integrating Babel, and internationalization in general, into your
9 application or framework. The code in this module is not used by Babel itself,
10 but instead is provided to address common requirements of applications that
11 should handle internationalization.
12
13
14 ---------------
15 Lazy Evaluation
16 ---------------
17
18 One such requirement is lazy evaluation of translations. Many web-based
19 applications define some localizable message at the module level, or in general
20 at some level where the locale of the remote user is not yet known. For such
21 cases, web frameworks generally provide a "lazy" variant of the ``gettext``
22 functions, which basically translates the message not when the ``gettext``
23 function is invoked, but when the string is accessed in some manner.
24
25
26 ---------------------------
27 Extended Translations Class
28 ---------------------------
29
30 Many web-based applications are composed of a variety of different components
31 (possibly using some kind of plugin system), and some of those components may
32 provide their own message catalogs that need to be integrated into the larger
33 system.
34
35 To support this usage pattern, Babel provides a ``Translations`` class that is
36 derived from the ``GNUTranslations`` class in the ``gettext`` module. This
37 class adds a ``merge()`` method that takes another ``Translations`` instance,
38 and merges the content of the latter into the main catalog:
39
40 .. code-block:: python
41
42 translations = Translations.load('main')
43 translations.merge(Translations.load('plugin1'))