{"parents": [], "prev": {"link": "../", "title": "Welcome to polib\u2019s documentation!"}, "next": {"link": "../installation/", "title": "Installation guide"}, "title": "Quick start guide", "meta": {}, "body": "<section id=\"quick-start-guide\">\n<span id=\"quickstart\"></span><h1>Quick start guide<a class=\"headerlink\" href=\"#quick-start-guide\" title=\"Link to this heading\">\u00b6</a></h1>\n<section id=\"installing-polib\">\n<h2>Installing polib<a class=\"headerlink\" href=\"#installing-polib\" title=\"Link to this heading\">\u00b6</a></h2>\n<p>polib requires python 2.7 or superior.</p>\n<p>There are several ways to install polib, this is explained\nin <a class=\"reference internal\" href=\"../installation/#installation\"><span class=\"std std-ref\">the installation section</span></a>.</p>\n<p>For the impatient, the easiest method is to install polib via\n<a class=\"reference external\" href=\"http://pip.openplans.org/\">pip</a>, just type:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"n\">pip</span> <span class=\"n\">install</span> <span class=\"n\">polib</span>\n</pre></div>\n</div>\n</section>\n<section id=\"some-basics-about-gettext-catalogs\">\n<h2>Some basics about gettext catalogs<a class=\"headerlink\" href=\"#some-basics-about-gettext-catalogs\" title=\"Link to this heading\">\u00b6</a></h2>\n<p>A gettext catalog is made up of many entries, each entry holding the relation\nbetween an original untranslated string and its corresponding translation.</p>\n<p>All entries in a given catalog usually pertain to a single project, and all\ntranslations are expressed in a single target language. One PO file entry has\nthe following schematic structure:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"c1\">#  translator-comments</span>\n<span class=\"c1\">#. extracted-comments</span>\n<span class=\"c1\">#: reference...</span>\n<span class=\"c1\">#, flag...</span>\n<span class=\"n\">msgid</span> <span class=\"n\">untranslated</span><span class=\"o\">-</span><span class=\"n\">string</span>\n<span class=\"n\">msgstr</span> <span class=\"n\">translated</span><span class=\"o\">-</span><span class=\"n\">string</span>\n</pre></div>\n</div>\n<p>A simple entry can look like this:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"c1\">#: lib/error.c:116</span>\n<span class=\"n\">msgid</span> <span class=\"s2\">&quot;Unknown system error&quot;</span>\n<span class=\"n\">msgstr</span> <span class=\"s2\">&quot;Error desconegut del sistema&quot;</span>\n</pre></div>\n</div>\n<p>polib has two main entry points for working with gettext catalogs:</p>\n<ul class=\"simple\">\n<li><p>the <a class=\"reference internal\" href=\"../api/#polib.pofile\" title=\"polib.pofile\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">pofile()</span></code></a> and <a class=\"reference internal\" href=\"../api/#polib.mofile\" title=\"polib.mofile\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">mofile()</span></code></a> functions to <strong>load</strong>\nexisting po or mo files,</p></li>\n<li><p>the <a class=\"reference internal\" href=\"../api/#polib.POFile\" title=\"polib.POFile\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">POFile</span></code></a> and <a class=\"reference internal\" href=\"../api/#polib.MOFile\" title=\"polib.MOFile\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">MOFile</span></code></a> classes to <strong>create</strong>\nnew po or mo files.</p></li>\n</ul>\n<p>References</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference external\" href=\"http://www.gnu.org/software/gettext/manual/\">Gettext Manual</a></p></li>\n<li><p><a class=\"reference external\" href=\"http://www.gnu.org/software/gettext/manual/html_node/gettext_9.html\">PO file format</a></p></li>\n<li><p><a class=\"reference external\" href=\"http://www.gnu.org/software/gettext/manual/html_node/gettext_136.html\">MO file format</a></p></li>\n</ul>\n</section>\n<section id=\"loading-existing-catalogs\">\n<h2>Loading existing catalogs<a class=\"headerlink\" href=\"#loading-existing-catalogs\" title=\"Link to this heading\">\u00b6</a></h2>\n<section id=\"loading-a-catalog-and-detecting-its-encoding\">\n<h3>Loading a catalog and detecting its encoding<a class=\"headerlink\" href=\"#loading-a-catalog-and-detecting-its-encoding\" title=\"Link to this heading\">\u00b6</a></h3>\n<p>Here the encoding of the po file is auto-detected by polib (polib detects it by\nparsing the charset in the header of the pofile):</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n<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=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n</section>\n<section id=\"loading-a-catalog-and-specifying-explicitly-the-encoding\">\n<h3>Loading a catalog and specifying explicitly the encoding<a class=\"headerlink\" href=\"#loading-a-catalog-and-specifying-explicitly-the-encoding\" title=\"Link to this heading\">\u00b6</a></h3>\n<p>For some reason you may want to specify the file encoding explicitly (because\nthe charset is not specified in the po file header for example), to do so:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n<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>\n    <span class=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">,</span>\n    <span class=\"n\">encoding</span><span class=\"o\">=</span><span class=\"s1\">&#39;iso-8859-15&#39;</span>\n<span class=\"p\">)</span>\n</pre></div>\n</div>\n</section>\n</section>\n<section id=\"loading-a-catalog-from-a-string\">\n<h2>Loading a catalog from a string<a class=\"headerlink\" href=\"#loading-a-catalog-from-a-string\" title=\"Link to this heading\">\u00b6</a></h2>\n<p>If you have a catalog as a string variable, you can load it simply like this:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n<span class=\"n\">po_str</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;&#39;&#39;</span>\n<span class=\"s1\">msgid &quot;&quot;</span>\n<span class=\"s1\">msgstr &quot;&quot;</span>\n<span class=\"s1\">&quot;Project-Id-Version: django</span><span class=\"se\">\\n</span><span class=\"s1\">&quot;</span>\n\n<span class=\"s1\">msgid &quot;foo&quot;</span>\n<span class=\"s1\">msgstr &quot;bar&quot;</span>\n<span class=\"s1\">&#39;&#39;&#39;</span>\n<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_str</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n<section id=\"loading-an-mo-file\">\n<h3>Loading an mo file<a class=\"headerlink\" href=\"#loading-an-mo-file\" title=\"Link to this heading\">\u00b6</a></h3>\n<p>In some cases you can be forced to load an mo file (because the po file is not\navailable for example), polib handles this case:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n<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=\"s1\">&#39;path/to/catalog.mo&#39;</span><span class=\"p\">)</span>\n<span class=\"nb\">print</span><span class=\"p\">(</span><span class=\"n\">mo</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n<p>As for po files, mofile also allows specifying the encoding explicitly.</p>\n</section>\n</section>\n<section id=\"loading-an-mo-file-from-a-bytes-object\">\n<h2>Loading an mo file from a bytes object<a class=\"headerlink\" href=\"#loading-an-mo-file-from-a-bytes-object\" title=\"Link to this heading\">\u00b6</a></h2>\n<p>If you have a bytes representation of a n mo file in a variable,\nyou can load it simply like this:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n<span class=\"n\">mo_bytes</span> <span class=\"o\">=</span> <span class=\"sa\">b</span><span class=\"s2\">&quot;</span><span class=\"se\">\\xde\\x12\\x04\\x95\\x00\\x00\\x00\\x00\\x05\\x00\\x00\\x00\\x1c\\x00\\x00\\x00</span><span class=\"s2\">D</span><span class=\"se\">\\x00\\x00\\x00\\x07\\x00\\x00\\x00</span><span class=\"s2\">l</span><span class=\"se\">\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x88\\x00\\x00\\x00\\x10\\x00\\x00\\x00\\x89\\x00\\x00\\x00\\x07\\x00\\x00\\x00\\x9a\\x00\\x00\\x00\\x0c\\x00\\x00\\x00\\xa2\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\xaf\\x00\\x00\\x00</span><span class=\"s2\">(</span><span class=\"se\">\\x00\\x00\\x00\\xbb\\x00\\x00\\x00\\n\\x00\\x00\\x00\\xe4\\x00\\x00\\x00\\x10\\x00\\x00\\x00\\xef\\x00\\x00\\x00\\x0f\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x16\\x00\\x00\\x00\\x10\\x01\\x00\\x00\\x01\\x00\\x00\\x00\\x03\\x00\\x00\\x00\\x05\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x04\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x00</span><span class=\"s2\">SNAR_BEZEICHNUNG</span><span class=\"se\">\\x00</span><span class=\"s2\">conform</span><span class=\"se\">\\x00</span><span class=\"s2\">inconclusive</span><span class=\"se\">\\x00</span><span class=\"s2\">non-conform</span><span class=\"se\">\\x00</span><span class=\"s2\">Content-Type: text/plain; charset=UTF-8</span><span class=\"se\">\\n\\x00</span><span class=\"s2\">Feldfrucht</span><span class=\"se\">\\x00\\xc3\\x9c</span><span class=\"s2\">bereinstimmung</span><span class=\"se\">\\x00</span><span class=\"s2\">Nicht eindeutig</span><span class=\"se\">\\x00</span><span class=\"s2\">Keine </span><span class=\"se\">\\xc3\\x9c</span><span class=\"s2\">bereinstimmung</span><span class=\"se\">\\x00</span><span class=\"s2\">&quot;</span>\n<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=\"n\">mo_bytes</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n</section>\n<section id=\"creating-po-catalogs-from-scratch\">\n<h2>Creating po catalogs from scratch<a class=\"headerlink\" href=\"#creating-po-catalogs-from-scratch\" title=\"Link to this heading\">\u00b6</a></h2>\n<p>polib allows you to create catalog from scratch, this can be done with the\nPOFile class, for example to create a simple catalog you could do:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n\n<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>\n<span class=\"n\">po</span><span class=\"o\">.</span><span class=\"n\">metadata</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s1\">&#39;Project-Id-Version&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;1.0&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Report-Msgid-Bugs-To&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;you@example.com&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;POT-Creation-Date&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;2007-10-18 14:00+0100&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;PO-Revision-Date&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;2007-10-18 14:00+0100&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Last-Translator&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;you &lt;you@example.com&gt;&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Language-Team&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;English &lt;yourteam@example.com&gt;&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;MIME-Version&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;1.0&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Content-Type&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;text/plain; charset=utf-8&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Content-Transfer-Encoding&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;8bit&#39;</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</pre></div>\n</div>\n<p>This snippet creates an empty pofile, with its metadata, and now you can add\nyou entries to the po file like this:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><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>\n    <span class=\"n\">msgid</span><span class=\"o\">=</span><span class=\"sa\">u</span><span class=\"s1\">&#39;Welcome&#39;</span><span class=\"p\">,</span>\n    <span class=\"n\">msgstr</span><span class=\"o\">=</span><span class=\"sa\">u</span><span class=\"s1\">&#39;Bienvenue&#39;</span><span class=\"p\">,</span>\n    <span class=\"n\">occurrences</span><span class=\"o\">=</span><span class=\"p\">[(</span><span class=\"s1\">&#39;welcome.py&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;12&#39;</span><span class=\"p\">),</span> <span class=\"p\">(</span><span class=\"s1\">&#39;anotherfile.py&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;34&#39;</span><span class=\"p\">)]</span>\n<span class=\"p\">)</span>\n<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>\n</pre></div>\n</div>\n<p>To save your file to the disk you would just do:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"n\">po</span><span class=\"o\">.</span><span class=\"n\">save</span><span class=\"p\">(</span><span class=\"s1\">&#39;/path/to/newfile.po&#39;</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n<p>And to compile the corresponding mo file:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"n\">po</span><span class=\"o\">.</span><span class=\"n\">save_as_mofile</span><span class=\"p\">(</span><span class=\"s1\">&#39;/path/to/newfile.mo&#39;</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n</section>\n<section id=\"more-examples\">\n<h2>More examples<a class=\"headerlink\" href=\"#more-examples\" title=\"Link to this heading\">\u00b6</a></h2>\n<section id=\"iterating-over-entries\">\n<h3>Iterating over entries<a class=\"headerlink\" href=\"#iterating-over-entries\" title=\"Link to this heading\">\u00b6</a></h3>\n<p>Iterating over <strong>all</strong> entries (by default POFiles contains all catalog\nentries, even obsolete and fuzzy entries):</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n\n<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=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">)</span>\n<span class=\"k\">for</span> <span class=\"n\">entry</span> <span class=\"ow\">in</span> <span class=\"n\">po</span><span class=\"p\">:</span>\n    <span class=\"nb\">print</span><span class=\"p\">(</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><span class=\"p\">)</span>\n</pre></div>\n</div>\n<p>Iterating over <strong>all</strong> entries except obsolete entries:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n\n<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=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">)</span>\n<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>\n<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>\n    <span class=\"nb\">print</span><span class=\"p\">(</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><span class=\"p\">)</span>\n</pre></div>\n</div>\n<p>Iterating over translated entries only:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n\n<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=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">)</span>\n<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>\n    <span class=\"nb\">print</span><span class=\"p\">(</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><span class=\"p\">)</span>\n</pre></div>\n</div>\n<p>And so on\u2026\nYou could also iterate over the list of POEntry objects returned by the\nfollowing POFile methods:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"../api/#polib.POFile.untranslated_entries\" title=\"polib.POFile.untranslated_entries\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">untranslated_entries()</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"../api/#polib.POFile.fuzzy_entries\" title=\"polib.POFile.fuzzy_entries\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">fuzzy_entries()</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"getting-the-percent-of-translated-entries\">\n<h3>Getting the percent of translated entries<a class=\"headerlink\" href=\"#getting-the-percent-of-translated-entries\" title=\"Link to this heading\">\u00b6</a></h3>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n\n<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=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">)</span>\n<span class=\"nb\">print</span><span class=\"p\">(</span><span class=\"n\">po</span><span class=\"o\">.</span><span class=\"n\">percent_translated</span><span class=\"p\">())</span>\n</pre></div>\n</div>\n</section>\n<section id=\"compiling-po-to-mo-files-and-reversing-mo-files-to-po-files\">\n<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=\"Link to this heading\">\u00b6</a></h3>\n<p>Compiling a po file:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span> <span class=\"nn\">polib</span>\n\n<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=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">)</span>\n<span class=\"c1\"># to get the binary representation in a variable:</span>\n<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>\n<span class=\"c1\"># or to save the po file as an mo file</span>\n<span class=\"n\">po</span><span class=\"o\">.</span><span class=\"n\">save_as_mofile</span><span class=\"p\">(</span><span class=\"s1\">&#39;path/to/catalog.mo&#39;</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n<p>Reverse a mo file to a po file:</p>\n<div class=\"highlight-default notranslate\"><div class=\"highlight\"><pre><span></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=\"s1\">&#39;path/to/catalog.mo&#39;</span><span class=\"p\">)</span>\n<span class=\"c1\"># to get the unicode representation in a variable, just do:</span>\n<span class=\"n\">podata</span> <span class=\"o\">=</span> <span class=\"n\">unicode</span><span class=\"p\">(</span><span class=\"n\">mo</span><span class=\"p\">)</span>\n<span class=\"c1\"># or to save the mo file as an po file</span>\n<span class=\"n\">mo</span><span class=\"o\">.</span><span class=\"n\">save_as_pofile</span><span class=\"p\">(</span><span class=\"s1\">&#39;path/to/catalog.po&#39;</span><span class=\"p\">)</span>\n</pre></div>\n</div>\n</section>\n</section>\n</section>\n", "metatags": "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n", "rellinks": [["genindex", "General Index", "I", "index"], ["installation", "Installation guide", "N", "next"], ["index", "Welcome to polib\u2019s documentation!", "P", "previous"]], "sourcename": "quickstart.rst.txt", "toc": "<ul>\n<li><a class=\"reference internal\" href=\"#\">Quick start guide</a><ul>\n<li><a class=\"reference internal\" href=\"#installing-polib\">Installing polib</a></li>\n<li><a class=\"reference internal\" href=\"#some-basics-about-gettext-catalogs\">Some basics about gettext catalogs</a></li>\n<li><a class=\"reference internal\" href=\"#loading-existing-catalogs\">Loading existing catalogs</a><ul>\n<li><a class=\"reference internal\" href=\"#loading-a-catalog-and-detecting-its-encoding\">Loading a catalog and detecting its encoding</a></li>\n<li><a class=\"reference internal\" href=\"#loading-a-catalog-and-specifying-explicitly-the-encoding\">Loading a catalog and specifying explicitly the encoding</a></li>\n</ul>\n</li>\n<li><a class=\"reference internal\" href=\"#loading-a-catalog-from-a-string\">Loading a catalog from a string</a><ul>\n<li><a class=\"reference internal\" href=\"#loading-an-mo-file\">Loading an mo file</a></li>\n</ul>\n</li>\n<li><a class=\"reference internal\" href=\"#loading-an-mo-file-from-a-bytes-object\">Loading an mo file from a bytes object</a></li>\n<li><a class=\"reference internal\" href=\"#creating-po-catalogs-from-scratch\">Creating po catalogs from scratch</a></li>\n<li><a class=\"reference internal\" href=\"#more-examples\">More examples</a><ul>\n<li><a class=\"reference internal\" href=\"#iterating-over-entries\">Iterating over entries</a></li>\n<li><a class=\"reference internal\" href=\"#getting-the-percent-of-translated-entries\">Getting the percent of translated entries</a></li>\n<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>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n", "display_toc": true, "page_source_suffix": ".rst", "current_page_name": "quickstart", "sidebars": ["localtoc.html", "relations.html", "sourcelink.html", "searchbox.html"], "alabaster_version": "1.0.0", "alabaster_version_info": [1, 0, 0]}