Your IP : 18.191.148.200
<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>babel.messages.mofile</title>
<link rel="stylesheet" href="epydoc.css" type="text/css" />
<script type="text/javascript" src="epydoc.js"></script>
</head>
<body bgcolor="white" text="black" link="blue" vlink="#204080"
alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
bgcolor="#a0c0ff" cellspacing="0">
<tr valign="middle">
<!-- Home link -->
<th> <a
href="babel-module.html">Home</a> </th>
<!-- Tree link -->
<th> <a
href="module-tree.html">Trees</a> </th>
<!-- Index link -->
<th> <a
href="identifier-index.html">Indices</a> </th>
<!-- Help link -->
<th> <a
href="help.html">Help</a> </th>
<!-- Project homepage -->
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center"
><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
</tr></table></th>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="100%">
<span class="breadcrumbs">
<a href="babel-module.html">Package babel</a> ::
<a href="babel.messages-module.html">Package messages</a> ::
Module mofile
</span>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<!-- hide/show private -->
</table>
</td>
</tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module mofile</h1><p class="nomargin-top"></p>
Writing of files in the <tt class="rst-rst-rst-rst-docutils literal rst-rst-rst-docutils literal rst-rst-docutils literal rst-docutils literal">gettext</tt> MO (machine object) format.
<hr />
<div class="fields"> <p><strong>Since:</strong>
version 0.9
</p>
<p><strong>See Also:</strong>
<a class="rst-reference external" href="http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files" target="_top">The Format of MO Files</a>
</p>
</div><!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td align="left" colspan="2" class="table-header">
<span class="table-header">Functions</span></td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="babel.messages.mofile-module.html#write_mo" class="summary-sig-name">write_mo</a>(<span class="summary-sig-arg">fileobj</span>,
<span class="summary-sig-arg">catalog</span>,
<span class="summary-sig-arg">use_fuzzy</span>=<span class="summary-sig-default">False</span>)</span><br />
Write a catalog to the specified file-like object using the GNU MO file
format.</td>
<td align="right" valign="top">
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- ==================== FUNCTION DETAILS ==================== -->
<a name="section-FunctionDetails"></a>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td align="left" colspan="2" class="table-header">
<span class="table-header">Function Details</span></td>
</tr>
</table>
<a name="write_mo"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">write_mo</span>(<span class="sig-arg">fileobj</span>,
<span class="sig-arg">catalog</span>,
<span class="sig-arg">use_fuzzy</span>=<span class="sig-default">False</span>)</span>
</h3>
</td><td align="right" valign="top"
>
</td>
</tr></table>
<p>Write a catalog to the specified file-like object using the GNU MO file
format.</p>
<pre class="py-doctest">
<span class="py-prompt">>>> </span><span class="py-keyword">from</span> babel.messages <span class="py-keyword">import</span> Catalog
<span class="py-prompt">>>> </span><span class="py-keyword">from</span> gettext <span class="py-keyword">import</span> GNUTranslations
<span class="py-prompt">>>> </span><span class="py-keyword">from</span> StringIO <span class="py-keyword">import</span> StringIO</pre>
<pre class="py-doctest">
<span class="py-prompt">>>> </span>catalog = Catalog(locale=<span class="py-string">'en_US'</span>)
<span class="py-prompt">>>> </span>catalog.add(<span class="py-string">'foo'</span>, <span class="py-string">'Voh'</span>)
<span class="py-prompt">>>> </span>catalog.add((u<span class="py-string">'bar'</span>, u<span class="py-string">'baz'</span>), (u<span class="py-string">'Bahr'</span>, u<span class="py-string">'Batz'</span>))
<span class="py-prompt">>>> </span>catalog.add(<span class="py-string">'fuz'</span>, <span class="py-string">'Futz'</span>, flags=[<span class="py-string">'fuzzy'</span>])
<span class="py-prompt">>>> </span>catalog.add(<span class="py-string">'Fizz'</span>, <span class="py-string">''</span>)
<span class="py-prompt">>>> </span>catalog.add((<span class="py-string">'Fuzz'</span>, <span class="py-string">'Fuzzes'</span>), (<span class="py-string">''</span>, <span class="py-string">''</span>))
<span class="py-prompt">>>> </span>buf = StringIO()</pre>
<pre class="py-doctest">
<span class="py-prompt">>>> </span>write_mo(buf, catalog)
<span class="py-prompt">>>> </span>buf.seek(0)
<span class="py-prompt">>>> </span>translations = GNUTranslations(fp=buf)
<span class="py-prompt">>>> </span>translations.ugettext(<span class="py-string">'foo'</span>)
<span class="py-output">u'Voh'</span>
<span class="py-output"></span><span class="py-prompt">>>> </span>translations.ungettext(<span class="py-string">'bar'</span>, <span class="py-string">'baz'</span>, 1)
<span class="py-output">u'Bahr'</span>
<span class="py-output"></span><span class="py-prompt">>>> </span>translations.ungettext(<span class="py-string">'bar'</span>, <span class="py-string">'baz'</span>, 2)
<span class="py-output">u'Batz'</span>
<span class="py-output"></span><span class="py-prompt">>>> </span>translations.ugettext(<span class="py-string">'fuz'</span>)
<span class="py-output">u'fuz'</span>
<span class="py-output"></span><span class="py-prompt">>>> </span>translations.ugettext(<span class="py-string">'Fizz'</span>)
<span class="py-output">u'Fizz'</span>
<span class="py-output"></span><span class="py-prompt">>>> </span>translations.ugettext(<span class="py-string">'Fuzz'</span>)
<span class="py-output">u'Fuzz'</span>
<span class="py-output"></span><span class="py-prompt">>>> </span>translations.ugettext(<span class="py-string">'Fuzzes'</span>)
<span class="py-output">u'Fuzzes'</span></pre>
<dl class="fields">
<dt>Parameters:</dt>
<dd><ul class="nomargin-top">
<li><strong class="pname"><code>fileobj</code></strong> - the file-like object to write to</li>
<li><strong class="pname"><code>catalog</code></strong> - the <a href="babel.messages.catalog.Catalog-class.html" class="link">Catalog</a> instance</li>
<li><strong class="pname"><code>use_fuzzy</code></strong> - whether translations marked as "fuzzy" should be included
in the output</li>
</ul></dd>
</dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
bgcolor="#a0c0ff" cellspacing="0">
<tr valign="middle">
<!-- Home link -->
<th> <a
href="babel-module.html">Home</a> </th>
<!-- Tree link -->
<th> <a
href="module-tree.html">Trees</a> </th>
<!-- Index link -->
<th> <a
href="identifier-index.html">Indices</a> </th>
<!-- Help link -->
<th> <a
href="help.html">Help</a> </th>
<!-- Project homepage -->
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center"
><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
</tr></table></th>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Mar 17 15:12:44 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
>http://epydoc.sourceforge.net</a>
</td>
</tr>
</table>
<script type="text/javascript">
<!--
// Private objects are initially displayed (because if
// javascript is turned off then we want them to be
// visible); but by default, we want to hide them. So hide
// them unless we have a cookie that says to show them.
checkCookie();
// -->
</script>
</body>
</html>