📄 node146.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.23.2.1 The NullTranslations class</title>
<META NAME="description" CONTENT="6.23.2.1 The NullTranslations class">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" HREF="node147.html" tppabs="http://www.python.org/doc/current/lib/node147.html">
<LINK REL="previous" HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html">
<LINK REL="up" HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html">
<LINK REL="next" HREF="node147.html" tppabs="http://www.python.org/doc/current/lib/node147.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node147.html" tppabs="http://www.python.org/doc/current/lib/node147.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html">6.23.2 Class-based API</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html">6.23.2 Class-based API</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node147.html" tppabs="http://www.python.org/doc/current/lib/node147.html">6.23.2.2 The GNUTranslations class</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H3><A NAME="SECTION0082321000000000000000">
6.23.2.1 The <tt class="class">NullTranslations</tt> class</A>
</H3>
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>:
<P>
<dl><dt><b><a name='l2h-1531'><tt class='method'>__init__</tt></a></b> (<big>[</big><var>fp</var><big>]</big>)
<dd>
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. It then calls
<code>self._parse(fp)</code> if <var>fp</var> is not <code>None</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-1532'><tt class='method'>_parse</tt></a></b> (<var>fp</var>)
<dd>
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>
<P>
<dl><dt><b><a name='l2h-1533'><tt class='method'>gettext</tt></a></b> (<var>message</var>)
<dd>
Return the translated message. Overridden in derived classes.
</dl>
<P>
<dl><dt><b><a name='l2h-1534'><tt class='method'>ugettext</tt></a></b> (<var>message</var>)
<dd>
Return the translated message as a Unicode string. Overridden in
derived classes.
</dl>
<P>
<dl><dt><b><a name='l2h-1535'><tt class='method'>info</tt></a></b> ()
<dd>
Return the ``protected'' <tt class="member">_info</tt> variable.
</dl>
<P>
<dl><dt><b><a name='l2h-1536'><tt class='method'>charset</tt></a></b> ()
<dd>
Return the ``protected'' <tt class="member">_charset</tt> variable.
</dl>
<P>
<dl><dt><b><a name='l2h-1537'><tt class='method'>install</tt></a></b> (<big>[</big><var>unicode</var><big>]</big>)
<dd>
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.
<P>
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
their module:
<P>
<dl><dd><pre class="verbatim">
import gettext
t = gettext.translation('mymodule', ...)
_ = t.gettext
</pre></dl>
<P>
This puts <tt class="function">_</tt> only in the module's global namespace and so
only affects calls within this module.
</dl>
<P>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node147.html" tppabs="http://www.python.org/doc/current/lib/node147.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html">6.23.2 Class-based API</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html">6.23.2 Class-based API</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node147.html" tppabs="http://www.python.org/doc/current/lib/node147.html">6.23.2.2 The GNUTranslations class</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -