My favorites | Sign in
Project Logo
       
Search
for
Updated Nov 27, 2009 by izimobil
Labels: Featured
Readme  

polib

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

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.

Installation

Note: chances are that polib is already packaged for your linux/bsd system, if so, we recommend you use your OS package system, if not then choose a method below:

Installing polib with setuptools

  $ easy_install polib

Installing polib with pip

  $ pip install polib

Installing polib from source

Download latest version from: http://code.google.com/p/polib/downloads/list

  $ tar xzfv polib-x.y.z.tar.gz
  $ cd polib-x.y.z
  $ python setup build
  $ sudo python setup.py install

Installing the polib development version

Note: this is not recommended in a production environment.

  $ hg clone https://polib.googlecode.com/hg/ polib  
  $ cd polib
  $ python setup build
  $ sudo python setup.py install

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 mo file
>>> po.save_as_mofile('tests/test_utf8.mo')

Documentation

A tutorial is available here and you will also find complete api documentation in the docs directory of the source tarball. You may want also browse it online: http://www.izimobil.org/polib/api/

Development

Bugtracker, wiki and svn repository can be found at: http://code.google.com/p/polib/

New released are published at python cheeseshop: http://cheeseshop.python.org/pypi/polib/

Credits

Author: David JEAN LOUIS <izimobil@gmail.com>

References


Sign in to add a comment
Hosted by Google Code