annotate doc/support.txt @ 546:10de195cfb04

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