HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //proc/thread-self/root/usr/share/doc/python27-babel-0.9.4/doc/support.html
<!DOCTYPE html>

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/">
<title>Support Classes and Functions</title>
<link rel="stylesheet" href="common/style/edgewall.css" type="text/css">
</head>
<body>
<div class="document" id="support-classes-and-functions">
    <div id="navigation">
      <span class="projinfo">Babel 0.9.4</span>
      <a href="index.html">Documentation Index</a>
    </div>
<h1 class="title">Support Classes and Functions</h1>
<div class="contents topic">
<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
<ul class="auto-toc simple">
<li><a class="reference" href="#lazy-evaluation" id="id1" name="id1">1   Lazy Evaluation</a></li>
<li><a class="reference" href="#extended-translations-class" id="id2" name="id2">2   Extended Translations Class</a></li>
</ul>
</div>
<p>The <tt class="docutils literal"><span class="pre">babel.support</span></tt> modules contains a number of classes and functions that
can help with integrating Babel, and internationalization in general, into your
application or framework. The code in this module is not used by Babel itself,
but instead is provided to address common requirements of applications that
should handle internationalization.</p>
<div class="section">
<h1><a id="lazy-evaluation" name="lazy-evaluation">1   Lazy Evaluation</a></h1>
<p>One such requirement is lazy evaluation of translations. Many web-based
applications define some localizable message at the module level, or in general
at some level where the locale of the remote user is not yet known. For such
cases, web frameworks generally provide a "lazy" variant of the <tt class="docutils literal"><span class="pre">gettext</span></tt>
functions, which basically translates the message not when the <tt class="docutils literal"><span class="pre">gettext</span></tt>
function is invoked, but when the string is accessed in some manner.</p>
</div>
<div class="section">
<h1><a id="extended-translations-class" name="extended-translations-class">2   Extended Translations Class</a></h1>
<p>Many web-based applications are composed of a variety of different components
(possibly using some kind of plugin system), and some of those components may
provide their own message catalogs that need to be integrated into the larger
system.</p>
<p>To support this usage pattern, Babel provides a <tt class="docutils literal"><span class="pre">Translations</span></tt> class that is
derived from the <tt class="docutils literal"><span class="pre">GNUTranslations</span></tt> class in the <tt class="docutils literal"><span class="pre">gettext</span></tt> module. This
class adds a <tt class="docutils literal"><span class="pre">merge()</span></tt> method that takes another <tt class="docutils literal"><span class="pre">Translations</span></tt> instance,
and merges the content of the latter into the main catalog:</p>
<div class="highlight"><pre><span class="n">translations</span> <span class="o">=</span> <span class="n">Translations</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s">'main'</span><span class="p">)</span>
<span class="n">translations</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">Translations</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s">'plugin1'</span><span class="p">))</span>
</pre></div>
</div>
    <div id="footer">
      Visit the Babel open source project at
      <a href="http://babel.edgewall.org/">http://babel.edgewall.org/</a>
    </div>
  </div>
</body>
</html>