1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
<?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.pofile</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 pofile
</span>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<!-- hide/show private -->
</table>
</td>
</tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module pofile</h1><br /><br />
Reading and 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"><span class="pre">gettext</span></tt> PO (portable object)
format.<br /><br />
<hr />
<div class="fields"> <p><strong>See Also:</strong>
<a class="rst-reference" href="http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files" target="_top">The Format of PO 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"><tt class="rst-docutils literal"><span class="pre">iterator</span></tt></span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="babel.messages.pofile-module.html#read_po" class="summary-sig-name">read_po</a>(<span class="summary-sig-arg">fileobj</span>,
<span class="summary-sig-arg">locale</span>=<span class="summary-sig-default"><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">territory_zones</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">001</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">[</code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-1</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-</code><code class="variable-ellipsis">...</code></span>,
<span class="summary-sig-arg">domain</span>=<span class="summary-sig-default"><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">territory_zones</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">001</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">[</code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-1</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-</code><code class="variable-ellipsis">...</code></span>,
<span class="summary-sig-arg">ignore_obsolete</span>=<span class="summary-sig-default">True</span>)</span><br />
Read messages from a <tt class="rst-docutils literal"><span class="pre">gettext</span></tt> PO (portable object) file from the given
file-like object and return a <a href="babel.messages.catalog.Catalog-class.html" class="link">Catalog</a>.</td>
<td align="right" valign="top">
</td>
</tr>
</table>
</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.pofile-module.html#write_po" class="summary-sig-name">write_po</a>(<span class="summary-sig-arg">fileobj</span>,
<span class="summary-sig-arg">catalog</span>,
<span class="summary-sig-arg">width</span>=<span class="summary-sig-default">76</span>,
<span class="summary-sig-arg">no_location</span>=<span class="summary-sig-default">True</span>,
<span class="summary-sig-arg">omit_header</span>=<span class="summary-sig-default">True</span>,
<span class="summary-sig-arg">sort_output</span>=<span class="summary-sig-default">True</span>,
<span class="summary-sig-arg">sort_by_file</span>=<span class="summary-sig-default">True</span>,
<span class="summary-sig-arg">ignore_obsolete</span>=<span class="summary-sig-default">True</span>,
<span class="summary-sig-arg">include_previous</span>=<span class="summary-sig-default">True</span>)</span><br />
Write a <tt class="rst-docutils literal"><span class="pre">gettext</span></tt> PO (portable object) template file for a given
message catalog to the provided file-like object.</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="read_po"></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">read_po</span>(<span class="sig-arg">fileobj</span>,
<span class="sig-arg">locale</span>=<span class="sig-default"><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">territory_zones</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">001</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">[</code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-1</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-</code><code class="variable-ellipsis">...</code></span>,
<span class="sig-arg">domain</span>=<span class="sig-default"><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">territory_zones</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">{</code><code class="variable-quote">'</code><code class="variable-string">001</code><code class="variable-quote">'</code><code class="variable-op">: </code><code class="variable-group">[</code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-1</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">Etc/GMT-</code><code class="variable-ellipsis">...</code></span>,
<span class="sig-arg">ignore_obsolete</span>=<span class="sig-default">True</span>)</span>
</h3>
</td><td align="right" valign="top"
>
</td>
</table>
<p>Read messages from a <tt class="rst-rst-docutils literal rst-docutils literal"><span class="pre">gettext</span></tt> PO (portable object) file from the given
file-like object and return a <a href="babel.messages.catalog.Catalog-class.html" class="link">Catalog</a>.</p>
<pre class="py-doctest">
<span class="py-prompt">>>> </span><span class="py-keyword">from</span> StringIO <span class="py-keyword">import</span> StringIO
<span class="py-prompt">>>> </span>buf = StringIO(<span class="py-string">'''</span>
<span class="py-more">... </span><span class="py-string">#: main.py:1</span>
<span class="py-more">... </span><span class="py-string">#, fuzzy, python-format</span>
<span class="py-more">... </span><span class="py-string">msgid "foo %(name)s"</span>
<span class="py-more">... </span><span class="py-string">msgstr ""</span>
<span class="py-more">...</span>
<span class="py-more">... </span><span class="py-string"># A user comment</span>
<span class="py-more">... </span><span class="py-string">#. An auto comment</span>
<span class="py-more">... </span><span class="py-string">#: main.py:3</span>
<span class="py-more">... </span><span class="py-string">msgid "bar"</span>
<span class="py-more">... </span><span class="py-string">msgid_plural "baz"</span>
<span class="py-more">... </span><span class="py-string">msgstr[0] ""</span>
<span class="py-more">... </span><span class="py-string">msgstr[1] ""</span>
<span class="py-more">... </span><span class="py-string">'''</span>)
<span class="py-prompt">>>> </span>catalog = read_po(buf)
<span class="py-prompt">>>> </span>catalog.revision_date = datetime(2007, 04, 01)</pre>
<pre class="py-doctest">
<span class="py-prompt">>>> </span><span class="py-keyword">for</span> message <span class="py-keyword">in</span> catalog:
<span class="py-more">... </span> <span class="py-keyword">if</span> message.id:
<span class="py-more">... </span> <span class="py-keyword">print</span> (message.id, message.string)
<span class="py-more">... </span> <span class="py-keyword">print</span> <span class="py-string">' '</span>, (message.locations, message.flags)
<span class="py-more">... </span> <span class="py-keyword">print</span> <span class="py-string">' '</span>, (message.user_comments, message.auto_comments)
<span class="py-output">(u'foo %(name)s', '')</span>
<span class="py-output"> ([(u'main.py', 1)], set([u'fuzzy', u'python-format']))</span>
<span class="py-output"> ([], [])</span>
<span class="py-output">((u'bar', u'baz'), ('', ''))</span>
<span class="py-output"> ([(u'main.py', 3)], set([]))</span>
<span class="py-output"> ([u'A user comment'], [u'An auto comment'])</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 read the PO file from</li>
<li><strong class="pname"><code>locale</code></strong> - the locale identifier or <a href="babel.core.Locale-class.html" class="link">Locale</a> object, or <code class="link">None</code>
if the catalog is not bound to a locale (which basically
means it's a template)</li>
<li><strong class="pname"><code>domain</code></strong> - the message domain</li>
<li><strong class="pname"><code>ignore_obsolete</code></strong> - whether to ignore obsolete messages in the input</li>
</ul></dd>
<dt>Returns: <tt class="rst-rst-docutils literal rst-docutils literal"><span class="pre">iterator</span></tt></dt>
<dd>an iterator over <tt class="rst-docutils literal"><span class="pre">(message,</span> <span class="pre">translation,</span> <span class="pre">location)</span></tt> tuples</dd>
</dl>
</td></tr></table>
</div>
<a name="write_po"></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_po</span>(<span class="sig-arg">fileobj</span>,
<span class="sig-arg">catalog</span>,
<span class="sig-arg">width</span>=<span class="sig-default">76</span>,
<span class="sig-arg">no_location</span>=<span class="sig-default">True</span>,
<span class="sig-arg">omit_header</span>=<span class="sig-default">True</span>,
<span class="sig-arg">sort_output</span>=<span class="sig-default">True</span>,
<span class="sig-arg">sort_by_file</span>=<span class="sig-default">True</span>,
<span class="sig-arg">ignore_obsolete</span>=<span class="sig-default">True</span>,
<span class="sig-arg">include_previous</span>=<span class="sig-default">True</span>)</span>
</h3>
</td><td align="right" valign="top"
>
</td>
</table>
<p>Write a <tt class="rst-rst-docutils literal rst-docutils literal"><span class="pre">gettext</span></tt> PO (portable object) template file for a given
message catalog to the provided file-like object.</p>
<pre class="py-doctest">
<span class="py-prompt">>>> </span>catalog = Catalog()
<span class="py-prompt">>>> </span>catalog.add(u<span class="py-string">'foo %(name)s'</span>, locations=[(<span class="py-string">'main.py'</span>, 1)],
<span class="py-more">... </span> flags=(<span class="py-string">'fuzzy'</span>,))
<span class="py-prompt">>>> </span>catalog.add((u<span class="py-string">'bar'</span>, u<span class="py-string">'baz'</span>), locations=[(<span class="py-string">'main.py'</span>, 3)])
<span class="py-prompt">>>> </span><span class="py-keyword">from</span> StringIO <span class="py-keyword">import</span> StringIO
<span class="py-prompt">>>> </span>buf = StringIO()
<span class="py-prompt">>>> </span>write_po(buf, catalog, omit_header=True)
<span class="py-prompt">>>> </span><span class="py-keyword">print</span> buf.getvalue()
<span class="py-output">#: main.py:1</span>
<span class="py-output">#, fuzzy, python-format</span>
<span class="py-output">msgid "foo %(name)s"</span>
<span class="py-output">msgstr ""</span>
<span class="py-output"><BLANKLINE></span>
<span class="py-output">#: main.py:3</span>
<span class="py-output">msgid "bar"</span>
<span class="py-output">msgid_plural "baz"</span>
<span class="py-output">msgstr[0] ""</span>
<span class="py-output">msgstr[1] ""</span>
<span class="py-output"><BLANKLINE></span>
<span class="py-output"><BLANKLINE></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>width</code></strong> - the maximum line width for the generated output; use <code class="link">None</code>,
0, or a negative number to completely disable line wrapping</li>
<li><strong class="pname"><code>no_location</code></strong> - do not emit a location comment for every message</li>
<li><strong class="pname"><code>omit_header</code></strong> - do not include the <tt class="rst-docutils literal"><span class="pre">msgid</span> <span class="pre">""</span></tt> entry at the top of the
output</li>
<li><strong class="pname"><code>sort_output</code></strong> - whether to sort the messages in the output by msgid</li>
<li><strong class="pname"><code>sort_by_file</code></strong> - whether to sort the messages in the output by their
locations</li>
<li><strong class="pname"><code>ignore_obsolete</code></strong> - whether to ignore obsolete messages and not include
them in the output; by default they are included as
comments</li>
<li><strong class="pname"><code>include_previous</code></strong> - include the old msgid as a comment when
updating the catalog</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.0beta1 on Fri Sep 7 12:36:49 2007
</td>
<td align="right" class="footer">
<a 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>
|