annotate doc/support.txt @ 552:9e8d6949eb86 trunk

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