/usr/share/doc/python-polib-doc/html/quickstart.html is in python-polib-doc 1.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 314 315 316 317 318 319 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quick start guide — polib 1.0.5 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="polib 1.0.5 documentation" href="index.html" />
<link rel="next" title="Installation guide" href="installation.html" />
<link rel="prev" title="Welcome to polib’s documentation!" href="index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="installation.html" title="Installation guide"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="Welcome to polib’s documentation!"
accesskey="P">previous</a> |</li>
<li><a href="index.html">polib 1.0.5 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="quick-start-guide">
<span id="quickstart"></span><h1>Quick start guide<a class="headerlink" href="#quick-start-guide" title="Permalink to this headline">¶</a></h1>
<div class="section" id="installing-polib">
<h2>Installing polib<a class="headerlink" href="#installing-polib" title="Permalink to this headline">¶</a></h2>
<p>polib requires python 2.5 or superior.</p>
<p>There are several ways to install polib, this is explained
in <a class="reference internal" href="installation.html#installation"><em>the installation section</em></a>.</p>
<p>For the impatient, the easiest method is to install polib via
<a class="reference external" href="http://pip.openplans.org/">pip</a>, just type:</p>
<div class="highlight-python"><div class="highlight"><pre>pip install polib
</pre></div>
</div>
</div>
<div class="section" id="some-basics-about-gettext-catalogs">
<h2>Some basics about gettext catalogs<a class="headerlink" href="#some-basics-about-gettext-catalogs" title="Permalink to this headline">¶</a></h2>
<p>A gettext catalog is made up of many entries, each entry holding the relation
between an original untranslated string and its corresponding translation.</p>
<p>All entries in a given catalog usually pertain to a single project, and all
translations are expressed in a single target language. One PO file entry has
the following schematic structure:</p>
<div class="highlight-python"><div class="highlight"><pre># translator-comments
#. extracted-comments
#: reference...
#, flag...
msgid untranslated-string
msgstr translated-string
</pre></div>
</div>
<p>A simple entry can look like this:</p>
<div class="highlight-python"><div class="highlight"><pre>#: lib/error.c:116
msgid "Unknown system error"
msgstr "Error desconegut del sistema"
</pre></div>
</div>
<p>polib has two main entry points for working with gettext catalogs:</p>
<ul class="simple">
<li>the <a class="reference internal" href="api.html#polib.pofile" title="polib.pofile"><tt class="xref py py-func docutils literal"><span class="pre">pofile()</span></tt></a> and <a class="reference internal" href="api.html#polib.mofile" title="polib.mofile"><tt class="xref py py-func docutils literal"><span class="pre">mofile()</span></tt></a> functions to <strong>load</strong>
existing po or mo files,</li>
<li>the <a class="reference internal" href="api.html#polib.POFile" title="polib.POFile"><tt class="xref py py-class docutils literal"><span class="pre">POFile</span></tt></a> and <a class="reference internal" href="api.html#polib.MOFile" title="polib.MOFile"><tt class="xref py py-class docutils literal"><span class="pre">MOFile</span></tt></a> classes to <strong>create</strong>
new po or mo files.</li>
</ul>
<p>References
* <a class="reference external" href="http://www.gnu.org/software/gettext/manual/">Gettext Manual</a>
* <a class="reference external" href="http://www.gnu.org/software/gettext/manual/html_node/gettext_9.html">PO file format</a>
* <a class="reference external" href="http://www.gnu.org/software/gettext/manual/html_node/gettext_136.html">MO file format</a></p>
</div>
<div class="section" id="loading-existing-catalogs">
<h2>Loading existing catalogs<a class="headerlink" href="#loading-existing-catalogs" title="Permalink to this headline">¶</a></h2>
<div class="section" id="loading-a-catalog-and-detecting-its-encoding">
<h3>Loading a catalog and detecting its encoding<a class="headerlink" href="#loading-a-catalog-and-detecting-its-encoding" title="Permalink to this headline">¶</a></h3>
<p>Here the encoding of the po file is auto-detected by polib (polib detects it by
parsing the charset in the header of the pofile):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">pofile</span><span class="p">(</span><span class="s">'path/to/catalog.po'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="loading-a-catalog-and-specifying-explicitly-the-encoding">
<h3>Loading a catalog and specifying explicitly the encoding<a class="headerlink" href="#loading-a-catalog-and-specifying-explicitly-the-encoding" title="Permalink to this headline">¶</a></h3>
<p>For some reason you may want to specify the file encoding explicitely (because
the charset is not specified in the po file header for example), to do so:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">pofile</span><span class="p">(</span>
<span class="s">'path/to/catalog.po'</span><span class="p">,</span>
<span class="n">encoding</span><span class="o">=</span><span class="s">'iso-8859-15'</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="loading-an-mo-file">
<h3>Loading an mo file<a class="headerlink" href="#loading-an-mo-file" title="Permalink to this headline">¶</a></h3>
<p>In some cases you can be forced to load an mo file (because the po file is not
available for example), polib handles this case:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">mo</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">mofile</span><span class="p">(</span><span class="s">'path/to/catalog.mo'</span><span class="p">)</span>
<span class="k">print</span> <span class="n">mo</span>
</pre></div>
</div>
<p>As for po files, mofile also allows to specify the encoding explicitely.</p>
</div>
</div>
<div class="section" id="creating-po-catalogs-from-scratch">
<h2>Creating po catalogs from scratch<a class="headerlink" href="#creating-po-catalogs-from-scratch" title="Permalink to this headline">¶</a></h2>
<p>polib allows you to create catalog from scratch, this can be done with the
POFile class, for exemple to create a simple catalog you could do:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">POFile</span><span class="p">()</span>
<span class="n">po</span><span class="o">.</span><span class="n">metadata</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">'Project-Id-Version'</span><span class="p">:</span> <span class="s">'1.0'</span><span class="p">,</span>
<span class="s">'Report-Msgid-Bugs-To'</span><span class="p">:</span> <span class="s">'you@example.com'</span><span class="p">,</span>
<span class="s">'POT-Creation-Date'</span><span class="p">:</span> <span class="s">'2007-10-18 14:00+0100'</span><span class="p">,</span>
<span class="s">'PO-Revision-Date'</span><span class="p">:</span> <span class="s">'2007-10-18 14:00+0100'</span><span class="p">,</span>
<span class="s">'Last-Translator'</span><span class="p">:</span> <span class="s">'you <you@example.com>'</span><span class="p">,</span>
<span class="s">'Language-Team'</span><span class="p">:</span> <span class="s">'English <yourteam@example.com>'</span><span class="p">,</span>
<span class="s">'MIME-Version'</span><span class="p">:</span> <span class="s">'1.0'</span><span class="p">,</span>
<span class="s">'Content-Type'</span><span class="p">:</span> <span class="s">'text/plain; charset=utf-8'</span><span class="p">,</span>
<span class="s">'Content-Transfer-Encoding'</span><span class="p">:</span> <span class="s">'8bit'</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This snippet creates an empty pofile, with its metadata, and now you can add
you entries to the po file like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">entry</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">POEntry</span><span class="p">(</span>
<span class="n">msgid</span><span class="o">=</span><span class="s">u'Welcome'</span><span class="p">,</span>
<span class="n">msgstr</span><span class="o">=</span><span class="s">u'Bienvenue'</span><span class="p">,</span>
<span class="n">occurrences</span><span class="o">=</span><span class="p">[(</span><span class="s">'welcome.py'</span><span class="p">,</span> <span class="s">'12'</span><span class="p">),</span> <span class="p">(</span><span class="s">'anotherfile.py'</span><span class="p">,</span> <span class="s">'34'</span><span class="p">)]</span>
<span class="p">)</span>
<span class="n">po</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">entry</span><span class="p">)</span>
</pre></div>
</div>
<p>To save your file to the disk you would just do:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">po</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s">'/path/to/newfile.po'</span><span class="p">)</span>
</pre></div>
</div>
<p>And to compile the corresponding mo file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">po</span><span class="o">.</span><span class="n">save_as_mofile</span><span class="p">(</span><span class="s">'/path/to/newfile.mo'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="more-examples">
<h2>More examples<a class="headerlink" href="#more-examples" title="Permalink to this headline">¶</a></h2>
<div class="section" id="iterating-over-entries">
<h3>Iterating over entries<a class="headerlink" href="#iterating-over-entries" title="Permalink to this headline">¶</a></h3>
<p>Iterating over <strong>all</strong> entries (by default POFiles contains all catalog
entries, even obsolete and fuzzy entries):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">pofile</span><span class="p">(</span><span class="s">'path/to/catalog.po'</span><span class="p">)</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">po</span><span class="p">:</span>
<span class="k">print</span> <span class="n">entry</span><span class="o">.</span><span class="n">msgid</span><span class="p">,</span> <span class="n">entry</span><span class="o">.</span><span class="n">msgstr</span>
</pre></div>
</div>
<p>Iterating over <strong>all</strong> entries except obsolete entries:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">pofile</span><span class="p">(</span><span class="s">'path/to/catalog.po'</span><span class="p">)</span>
<span class="n">valid_entries</span> <span class="o">=</span> <span class="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">po</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">e</span><span class="o">.</span><span class="n">obsolete</span><span class="p">]</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">valid_entries</span><span class="p">:</span>
<span class="k">print</span> <span class="n">entry</span><span class="o">.</span><span class="n">msgid</span><span class="p">,</span> <span class="n">entry</span><span class="o">.</span><span class="n">msgstr</span>
</pre></div>
</div>
<p>Iterating over translated entries only:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">pofile</span><span class="p">(</span><span class="s">'path/to/catalog.po'</span><span class="p">)</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">po</span><span class="o">.</span><span class="n">translated_entries</span><span class="p">():</span>
<span class="k">print</span> <span class="n">entry</span><span class="o">.</span><span class="n">msgid</span><span class="p">,</span> <span class="n">entry</span><span class="o">.</span><span class="n">msgstr</span>
</pre></div>
</div>
<p>And so on...
You could also iterate over the list of POEntry objects returned by the
following POFile methods:</p>
<ul class="simple">
<li><a class="reference internal" href="api.html#polib.POFile.untranslated_entries" title="polib.POFile.untranslated_entries"><tt class="xref py py-meth docutils literal"><span class="pre">untranslated_entries()</span></tt></a></li>
<li><a class="reference internal" href="api.html#polib.POFile.fuzzy_entries" title="polib.POFile.fuzzy_entries"><tt class="xref py py-meth docutils literal"><span class="pre">fuzzy_entries()</span></tt></a></li>
</ul>
</div>
<div class="section" id="getting-the-percent-of-translated-entries">
<h3>Getting the percent of translated entries<a class="headerlink" href="#getting-the-percent-of-translated-entries" title="Permalink to this headline">¶</a></h3>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">pofile</span><span class="p">(</span><span class="s">'path/to/catalog.po'</span><span class="p">)</span>
<span class="k">print</span> <span class="n">po</span><span class="o">.</span><span class="n">percent_translated</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="compiling-po-to-mo-files-and-reversing-mo-files-to-po-files">
<h3>Compiling po to mo files and reversing mo files to po files<a class="headerlink" href="#compiling-po-to-mo-files-and-reversing-mo-files-to-po-files" title="Permalink to this headline">¶</a></h3>
<p>Compiling a po file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">polib</span>
<span class="n">po</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">pofile</span><span class="p">(</span><span class="s">'path/to/catalog.po'</span><span class="p">)</span>
<span class="c"># to get the binary representation in a variable:</span>
<span class="n">modata</span> <span class="o">=</span> <span class="n">po</span><span class="o">.</span><span class="n">to_binary</span><span class="p">()</span>
<span class="c"># or to save the po file as an mo file</span>
<span class="n">po</span><span class="o">.</span><span class="n">save_as_mofile</span><span class="p">(</span><span class="s">'path/to/catalog.mo'</span><span class="p">)</span>
</pre></div>
</div>
<p>Reverse a mo file to a po file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">mo</span> <span class="o">=</span> <span class="n">polib</span><span class="o">.</span><span class="n">mofile</span><span class="p">(</span><span class="s">'path/to/catalog.mo'</span><span class="p">)</span>
<span class="c"># to get the unicode representation in a variable, just do:</span>
<span class="n">podata</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">mo</span><span class="p">)</span>
<span class="c"># or to save the mo file as an po file</span>
<span class="n">mo</span><span class="o">.</span><span class="n">save_as_pofile</span><span class="p">(</span><span class="s">'path/to/catalog.po'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Quick start guide</a><ul>
<li><a class="reference internal" href="#installing-polib">Installing polib</a></li>
<li><a class="reference internal" href="#some-basics-about-gettext-catalogs">Some basics about gettext catalogs</a></li>
<li><a class="reference internal" href="#loading-existing-catalogs">Loading existing catalogs</a><ul>
<li><a class="reference internal" href="#loading-a-catalog-and-detecting-its-encoding">Loading a catalog and detecting its encoding</a></li>
<li><a class="reference internal" href="#loading-a-catalog-and-specifying-explicitly-the-encoding">Loading a catalog and specifying explicitly the encoding</a></li>
<li><a class="reference internal" href="#loading-an-mo-file">Loading an mo file</a></li>
</ul>
</li>
<li><a class="reference internal" href="#creating-po-catalogs-from-scratch">Creating po catalogs from scratch</a></li>
<li><a class="reference internal" href="#more-examples">More examples</a><ul>
<li><a class="reference internal" href="#iterating-over-entries">Iterating over entries</a></li>
<li><a class="reference internal" href="#getting-the-percent-of-translated-entries">Getting the percent of translated entries</a></li>
<li><a class="reference internal" href="#compiling-po-to-mo-files-and-reversing-mo-files-to-po-files">Compiling po to mo files and reversing mo files to po files</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Welcome to polib’s documentation!</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="installation.html"
title="next chapter">Installation guide</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/quickstart.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="installation.html" title="Installation guide"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="Welcome to polib’s documentation!"
>previous</a> |</li>
<li><a href="index.html">polib 1.0.5 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2011, David Jean Louis <izimobil@gmail.com>.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
</div>
</body>
</html>
|