polib API¶
The pofile function¶
-
polib.pofile(pofile, **kwargs)[source]¶ Convenience function that parses the po or pot file
pofileand returns aPOFileinstance.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
-woption 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 aPOFileinstance).
The mofile function¶
-
polib.mofile(mofile, **kwargs)[source]¶ Convenience function that parses the mo file
mofileand returns aMOFileinstance.Arguments:
mofile- string, full or relative path to the mo file or its content (data).
wrapwidth- integer, the wrap width, only useful when the
-woption 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 aPOFileinstance).
The detect_encoding function¶
-
polib.detect_encoding(file, binary_mode=False)[source]¶ Try to detect the encoding used by the
file. Thefileargument 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 ofdefault_encoding.Arguments:
file- string, full or relative path to the po/mo file or its content.
binary_mode- boolean, set this to True if
fileis a mo file.
The escape function¶
The unescape function¶
The POFile class¶
-
class
polib.POFile(*args, **kwargs)[source]¶ Po (or Pot) file reader/writer. This class inherits the
_BaseFileclass and, by extension, the pythonlisttype.-
merge(refpot)[source]¶ Convenience method that merges the current pofile with the pot file provided. It behaves exactly as the gettext msgmerge utility:
- comments of this file will be preserved, but extracted comments and occurrences will be discarded;
- any translations or comments in the file will be discarded, however, dot comments and file positions will be preserved;
- the fuzzy flags are preserved.
Keyword argument:
refpot- object POFile, the reference catalog.
-
percent_translated()[source]¶ Convenience method that returns the percentage of translated messages.
-
The MOFile class¶
-
class
polib.MOFile(*args, **kwargs)[source]¶ Mo file reader/writer. This class inherits the
_BaseFileclass and, by extension, the pythonlisttype.-
save(fpath=None)[source]¶ Saves the mofile to
fpath.Keyword argument:
fpath- string, full or relative path to the file.
-