po.py

.po files related stuff.

mdpo.po.find_entry_in_entries(entry, entries, **kwargs)

Returns an equal entry in a set of polib.POEntry entries.

Finds the first polib.POEntry instance in the iterable entries that is equal, according to its __cmp__ method, to the polib.POEntry instance passed as entry argument.

Parameters
  • entry (polib.POEntry) – Entry to search for.

  • entries (list) – Entries to search against.

  • **kwargs – Keyword arguments passed to polib.POEntry.__cmp__().

Returns

Entry passed in entry argument if an equal entry has been found in entries iterable, otherwise None.

Return type

polib.POEntry

mdpo.po.mark_not_found_entries_as_obsoletes(pofile, entries)

Marks entries in a PO file obsoletes if are not in a set of entries.

If an entry of the PO file is found in the set of entries, will be marked as no obsolete.

Parameters
  • pofile (polib.POFile) – PO file in which the missing entries will be marked as obsoletes.

  • entries (list) – Entries to search against.

mdpo.po.paths_or_globs_to_unique_pofiles(pofiles_globs, ignore, po_encoding=None)

Converts any path, paths or glob to polib.POFile objects.

Parameters
  • pofiles_globs (str, list) – Can be a path, a glob, multiples paths or multiples globs.

  • ignore (list) – Paths to ignore.

  • po_encoding (str) – Encoding used reading the PO files.

Returns

Unique set of polib.POFile objects.

Return type

set

mdpo.po.po_escaped_string(chars)

Convenience function that prepends a \ character to a string.

This is used to escape values inside strings wrapped for the returned character.

Parameters

chars (str) – Value for which first character will be escaped.

Returns

First character of passed string with \ character prepended.

Return type

str

mdpo.po.pofiles_to_unique_translations_dicts(pofiles)

Extracts unique translations from a set of pofiles.

Given multiple pofiles, extracts translations (those messages with non empty msgstrs) into two dictionaries, a dictionary for translations with contexts and other without them.

Parameters

pofiles (list) – List of polib.POFile objects.

Returns

dictionaries with translations.

Return type

tuple

mdpo.po.remove_not_found_entries(pofile, entries)

Removes entries in a PO file if are not in a set of entries.

Parameters
  • pofile (polib.POFile) – PO file for which the missing entries will be removed.

  • entries (list) – Entries to search against.

mdpo.po.save_pofile_checking_file_changed(pofile, po_filepath)

Save a polib.POFile checking if the content has changed.

Parameters
  • pofile (polib.POFile) – POFile to save.

  • po_filepath (str) – Path to the new file to save in.

Returns

If the PO file content has been changed.

Return type

bool