<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"node330.html" />
<link rel=
"prev" href=
"node328.html" />
<link rel=
"parent" href=
"node328.html" />
<link rel=
"next" href=
"node330.html" />
<meta name='aesop' content='information'
/>
<title>6.28.2.1 The NullTranslations class
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.28.2 Class-based API"
href=
"node328.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6.28.2 Class-based API"
href=
"node328.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.28.2.2 The GNUTranslations class"
href=
"node330.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node328.html">6.28.2 Class-based API
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"node328.html">6.28.2 Class-based API
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"node330.html">6.28.2.2 The GNUTranslations class
</A>
<!--End of Navigation Panel-->
<H3><A NAME=
"SECTION0082821000000000000000">
6.28.2.1 The
<tt class=
"class">NullTranslations
</tt> class
</A>
Translation classes are what actually implement the translation of
original source file message strings to translated message strings.
The base class used by all translation classes is
<tt class=
"class">NullTranslations
</tt>; this provides the basic interface you can use
to write your own specialized translation classes. Here are the
methods of
<tt class=
"class">NullTranslations
</tt>:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2434' xml:id='l2h-
2434'
class=
"method">__init__
</tt></b>(
</nobr></td>
<td><var></var><big>[
</big><var>fp
</var><big>]
</big><var></var>)
</td></tr></table></dt>
Takes an optional file object
<var>fp
</var>, which is ignored by the base
class. Initializes ``protected'' instance variables
<var>_info
</var> and
<var>_charset
</var> which are set by derived classes, as well as
<var>_fallback
</var>,
which is set through
<tt class=
"method">add_fallback
</tt>. It then calls
<code>self._parse(fp)
</code> if
<var>fp
</var> is not
<code>None
</code>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2435' xml:id='l2h-
2435'
class=
"method">_parse
</tt></b>(
</nobr></td>
<td><var>fp
</var>)
</td></tr></table></dt>
No-op'd in the base class, this method takes file object
<var>fp
</var>, and
reads the data from the file, initializing its message catalog. If
you have an unsupported message catalog file format, you should
override this method to parse your format.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2436' xml:id='l2h-
2436'
class=
"method">add_fallback
</tt></b>(
</nobr></td>
<td><var>fallback
</var>)
</td></tr></table></dt>
Add
<var>fallback
</var> as the fallback object for the current translation
object. A translation object should consult the fallback if it cannot
provide a translation for a given message.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2437' xml:id='l2h-
2437'
class=
"method">gettext
</tt></b>(
</nobr></td>
<td><var>message
</var>)
</td></tr></table></dt>
If a fallback has been set, forward
<tt class=
"method">gettext()
</tt> to the fallback.
Otherwise, return the translated message. Overridden in derived classes.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2438' xml:id='l2h-
2438'
class=
"method">lgettext
</tt></b>(
</nobr></td>
<td><var>message
</var>)
</td></tr></table></dt>
If a fallback has been set, forward
<tt class=
"method">lgettext()
</tt> to the fallback.
Otherwise, return the translated message. Overridden in derived classes.
<span class=
"versionnote">New in version
2.4.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2439' xml:id='l2h-
2439'
class=
"method">ugettext
</tt></b>(
</nobr></td>
<td><var>message
</var>)
</td></tr></table></dt>
If a fallback has been set, forward
<tt class=
"method">ugettext()
</tt> to the fallback.
Otherwise, return the translated message as a Unicode string.
Overridden in derived classes.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2440' xml:id='l2h-
2440'
class=
"method">ngettext
</tt></b>(
</nobr></td>
<td><var>singular, plural, n
</var>)
</td></tr></table></dt>
If a fallback has been set, forward
<tt class=
"method">ngettext()
</tt> to the fallback.
Otherwise, return the translated message. Overridden in derived classes.
<span class=
"versionnote">New in version
2.3.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2441' xml:id='l2h-
2441'
class=
"method">lngettext
</tt></b>(
</nobr></td>
<td><var>singular, plural, n
</var>)
</td></tr></table></dt>
If a fallback has been set, forward
<tt class=
"method">ngettext()
</tt> to the fallback.
Otherwise, return the translated message. Overridden in derived classes.
<span class=
"versionnote">New in version
2.4.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2442' xml:id='l2h-
2442'
class=
"method">ungettext
</tt></b>(
</nobr></td>
<td><var>singular, plural, n
</var>)
</td></tr></table></dt>
If a fallback has been set, forward
<tt class=
"method">ungettext()
</tt> to the fallback.
Otherwise, return the translated message as a Unicode string.
Overridden in derived classes.
<span class=
"versionnote">New in version
2.3.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2443' xml:id='l2h-
2443'
class=
"method">info
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return the ``protected''
<tt class=
"member">_info
</tt> variable.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2444' xml:id='l2h-
2444'
class=
"method">charset
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return the ``protected''
<tt class=
"member">_charset
</tt> variable.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2445' xml:id='l2h-
2445'
class=
"method">output_charset
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return the ``protected''
<tt class=
"member">_output_charset
</tt> variable, which
defines the encoding used to return translated messages.
<span class=
"versionnote">New in version
2.4.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2446' xml:id='l2h-
2446'
class=
"method">set_output_charset
</tt></b>(
</nobr></td>
<td><var>charset
</var>)
</td></tr></table></dt>
Change the ``protected''
<tt class=
"member">_output_charset
</tt> variable, which
defines the encoding used to return translated messages.
<span class=
"versionnote">New in version
2.4.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2447' xml:id='l2h-
2447'
class=
"method">install
</tt></b>(
</nobr></td>
<td><var></var><big>[
</big><var>unicode
</var><big>]
</big><var></var>)
</td></tr></table></dt>
If the
<var>unicode
</var> flag is false, this method installs
<tt class=
"method">self.gettext()
</tt> into the built-in namespace, binding it to
"<tt class="samp
">_</tt>". If
<var>unicode
</var> is true, it binds
<tt class=
"method">self.ugettext()
</tt>
instead. By default,
<var>unicode
</var> is false.
Note that this is only one way, albeit the most convenient way, to
make the
<tt class=
"function">_
</tt> function available to your application. Because it
affects the entire application globally, and specifically the built-in
namespace, localized modules should never install
<tt class=
"function">_
</tt>.
Instead, they should use this code to make
<tt class=
"function">_
</tt> available to
<div class=
"verbatim"><pre>
t = gettext.translation('mymodule', ...)
This puts
<tt class=
"function">_
</tt> only in the module's global namespace and so
only affects calls within this module.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.28.2 Class-based API"
href=
"node328.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6.28.2 Class-based API"
href=
"node328.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.28.2.2 The GNUTranslations class"
href=
"node330.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node328.html">6.28.2 Class-based API
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"node328.html">6.28.2 Class-based API
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"node330.html">6.28.2.2 The GNUTranslations class
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.