Package horizons :: Package ext :: Module polib
[hide private]
[frames] | no frames]

Module polib

source code

**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 via the :func:`~polib.pofile` and :func:`~polib.mofile` convenience functions.


Version: 1.0.3

Author: David Jean Louis <izimobil@gmail.com>

Classes [hide private]
  _BaseFile
Common base class for the :class:`~polib.POFile` and :class:`~polib.MOFile` classes.
  POFile
Po (or Pot) file reader/writer.
  MOFile
Mo file reader/writer.
  _BaseEntry
Base class for :class:`~polib.POEntry` and :class:`~polib.MOEntry` classes.
  POEntry
Represents a po file entry.
  MOEntry
Represents a mo file entry.
  _POFileParser
A finite state machine to parse efficiently and correctly po file format.
  _MOFileParser
A class to parse binary mo files.
  TextWrapper
Subclass of textwrap.TextWrapper that backport the drop_whitespace option.
Functions [hide private]
 
b(s) source code
 
u(s) source code
 
_pofile_or_mofile(f, type, **kwargs)
Internal function used by :func:`polib.pofile` and :func:`polib.mofile` to honor the DRY concept.
source code
 
pofile(pofile, **kwargs)
Convenience function that parses the po or pot file ``pofile`` and returns a :class:`~polib.POFile` instance.
source code
 
mofile(mofile, **kwargs)
Convenience function that parses the mo file ``mofile`` and returns a :class:`~polib.MOFile` instance.
source code
 
detect_encoding(file, binary_mode=False)
Try to detect the encoding used by the ``file``.
source code
 
escape(st)
Escapes the characters ``\\``, ``\t``, ``\n``, ``\r`` and ``"`` in the given string ``st`` and returns it.
source code
 
unescape(st)
Unescapes the characters ``\\``, ``\t``, ``\n``, ``\r`` and ``"`` in the given string ``st`` and returns it.
source code
 
wrap(text, width=70, **kwargs)
Wrap a single paragraph of text, returning a list of wrapped lines.
source code
Variables [hide private]
  default_encoding = 'utf-8'
  PY3 = False
  __package__ = 'horizons.ext'
Function Details [hide private]

pofile(pofile, **kwargs)

source code 

Convenience function that parses the po or pot file ``pofile`` and returns
a :class:`~polib.POFile` instance.

Arguments:

``pofile``
    string, full or relative path to the po/pot file or its content (data).

``wrapwidth``
    integer, the wrap width, only useful when the ``-w`` option was passed
    to xgettext (optional, default: ``78``).

``encoding``
    string, the encoding to use (e.g. "utf-8") (default: ``None``, the
    encoding will be auto-detected).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file (optional, default: ``False``).

``klass``
    class which is used to instantiate the return value (optional,
    default: ``None``, the return value with be a :class:`~polib.POFile`
    instance).

mofile(mofile, **kwargs)

source code 

Convenience function that parses the mo file ``mofile`` and returns a
:class:`~polib.MOFile` instance.

Arguments:

``mofile``
    string, full or relative path to the mo file or its content (data).

``wrapwidth``
    integer, the wrap width, only useful when the ``-w`` option was passed
    to xgettext to generate the po file that was used to format the mo file
    (optional, default: ``78``).

``encoding``
    string, the encoding to use (e.g. "utf-8") (default: ``None``, the
    encoding will be auto-detected).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file (optional, default: ``False``).

``klass``
    class which is used to instantiate the return value (optional,
    default: ``None``, the return value with be a :class:`~polib.POFile`
    instance).

detect_encoding(file, binary_mode=False)

source code 

Try to detect the encoding used by the ``file``. The ``file`` argument can
be a PO or MO file path or a string containing the contents of the file.
If the encoding cannot be detected, the function will return the value of
``default_encoding``.

Arguments:

``file``
    string, full or relative path to the po/mo file or its content.

``binary_mode``
    boolean, set this to True if ``file`` is a mo file.