mdpo.po module

PO files related stuff.

mdpo.po.check_empty_msgstrs_in_filepaths(filenames)

Warns about all empty msgstr found in a set of PO files.

Parameters:

filenames (list) – Set of file names to check.

Returns:

error messages produced.

Return type:

list(str)

mdpo.po.check_fuzzy_entries_in_filepaths(filenames)

Warns about all fuzzy entries found in a set of PO files.

Parameters:

filenames (list) – Set of file names to check.

Returns:

error messages produced.

Return type:

list(str)

mdpo.po.check_obsolete_entries_in_filepaths(filenames)

Warns about all obsolete entries found in a set of PO files.

Parameters:

filenames (list) – Set of file names to check.

Returns:

error messages produced.

Return type:

list(str)

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

Return 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__ method.

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)

Mark 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.parse_empty_msgstr_from_content_lines(content_lines, location_prefix='line ')

Warns about all empty msgstr found in a set of PO files.

Parameters:
  • content_lines (list) – Set of content lines to check.

  • location_prefix (str) – Prefix to use in the location message.

Returns:

error locations found.

Return type:

list(str)

mdpo.po.parse_fuzzy_from_content_lines(content_lines, location_prefix='line ')

Warns about all fuzzy entries found in a set of PO files.

Parameters:
  • content_lines (list) – Set of content lines to check.

  • location_prefix (str) – Prefix to use in the location message.

Returns:

error locations found.

Return type:

list(str)

mdpo.po.parse_obsoletes_from_content_lines(content_lines, location_prefix='line ')

Warns about all obsolete entries found in a set of PO files.

Parameters:
  • content_lines (list) – Set of content lines to check.

  • location_prefix (str) – Prefix to use in the location message.

Returns:

error locations found.

Return type:

list(str)

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

Convert 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)

Prepend 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)

Extract unique translations from a set of PO files.

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)

Remove 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.