📄 node147.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.23.2.2 The GNUTranslations class</title>
<META NAME="description" CONTENT="6.23.2.2 The GNUTranslations 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="node148.html" tppabs="http://www.python.org/doc/current/lib/node148.html">
<LINK REL="previous" HREF="node146.html" tppabs="http://www.python.org/doc/current/lib/node146.html">
<LINK REL="up" HREF="node145.html" tppabs="http://www.python.org/doc/current/lib/node145.html">
<LINK REL="next" HREF="node148.html" tppabs="http://www.python.org/doc/current/lib/node148.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node146.html" tppabs="http://www.python.org/doc/current/lib/node146.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="node148.html" tppabs="http://www.python.org/doc/current/lib/node148.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="node146.html" tppabs="http://www.python.org/doc/current/lib/node146.html">6.23.2.1 The NullTranslations class</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="node148.html" tppabs="http://www.python.org/doc/current/lib/node148.html">6.23.2.3 Solaris message catalog</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H3><A NAME="SECTION0082322000000000000000">
6.23.2.2 The <tt class="class">GNUTranslations</tt> class</A>
</H3>
<P>
The <tt class="module">gettext</tt> module provides one additional class derived from
<tt class="class">NullTranslations</tt>: <tt class="class">GNUTranslations</tt>. This class
overrides <tt class="method">_parse()</tt> to enable reading GNU <b class="program">gettext</b>
format <span class="file">.mo</span> files in both big-endian and little-endian format.
<P>
It also parses optional meta-data out of the translation catalog. It
is convention with GNU <b class="program">gettext</b> to include meta-data as the
translation for the empty string. This meta-data is in <a class="rfc" name="rfcref-46259"
href="javascript:if(confirm('http://www.ietf.org/rfc/rfc0822.txt \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc0822.txt'" tppabs="http://www.ietf.org/rfc/rfc0822.txt">RFC 822 <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a>-style
<code>key: value</code> pairs. If the key <code>Content-Type</code> is found,
then the <code>charset</code> property is used to initialize the
``protected'' <tt class="member">_charset</tt> instance variable. The entire set of
key/value pairs are placed into a dictionary and set as the
``protected'' <tt class="member">_info</tt> instance variable.
<P>
If the <span class="file">.mo</span> file's magic number is invalid, or if other problems
occur while reading the file, instantiating a <tt class="class">GNUTranslations</tt> class
can raise <tt class="exception">IOError</tt>.
<P>
The other usefully overridden method is <tt class="method">ugettext()</tt>, which
returns a Unicode string by passing both the translated message string
and the value of the ``protected'' <tt class="member">_charset</tt> variable to the
builtin <tt class="function">unicode()</tt> function.
<P>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node146.html" tppabs="http://www.python.org/doc/current/lib/node146.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="node148.html" tppabs="http://www.python.org/doc/current/lib/node148.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="node146.html" tppabs="http://www.python.org/doc/current/lib/node146.html">6.23.2.1 The NullTranslations class</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="node148.html" tppabs="http://www.python.org/doc/current/lib/node148.html">6.23.2.3 Solaris message catalog</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 + -