Skip to main content

A library to manipulate gettext files (po and mo files).

Project description

polib allows you to manipulate, create, modify gettext files (pot, po and mo files). You can load existing files, iterate through it’s entries, add, modify entries, comments or metadata, etc… or create new po files from scratch.

polib provides a simple and pythonic API, exporting only three convenience functions pofile, mofile and detect_encoding, and the 4 core classes: POFile, MOFile, POEntry and MOEntry for creating new files/entries.

What’s new in version 0.4.0

  • fixed bug #0005: percent_translated divide by 0 on empty po files,
  • fixed bug #0004: occurences that have hiphens are wrapped when they should not,
  • changes in how encoding is handled,
  • remove deprecation warnings for typo occurences,
  • added POEntry.__cmp__() method to sort entries like gettext does,
  • fixed POEntry.translated(),
  • fixed some bugs in mo files parsing,
  • added a merge method to POFile, that behaves like the gettext msgmerge utility,
  • renamed quote/unquote functions to escape/unescape,
  • various cosmetic changes.

Basic usage example

>>> import polib
>>> # load an existing po file
>>> po = polib.pofile('tests/test_utf8.po')
>>> for entry in po:
...     # do something with entry...
...     print entry.msgid, entry.msgstr
>>> # add an entry
>>> entry = polib.POEntry(msgid='Welcome', msgstr='Bienvenue')
>>> entry.occurences = [('welcome.py', '12'), ('anotherfile.py', '34')]
>>> po.append(entry)
>>> # save our modified po file
>>> po.save()
>>> # compile it to a mo file
>>> po.save_as_mofile('tests/test_utf8.mo')

Download it from here and visit: http://code.google.com/p/polib/

Project details


Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page