translations

Models

class POFile(*args, **kwargs)

A POFile is a representation of a PO file structure.

It can either be a real PO file on a repository, a dynamically-generated one, etc. It represents the translation of a component to a language. The model’s basic use is the calculation of translation statistics.

calculate_perc()
Update normalized percentage statistics fields.
object
Provides a generic relation to any object through content-type/object-id fields.
symbolic_path
Return a path in the form project/component/pofile_path.
class POFileLock(*args, **kwargs)
A lock/hold on a POFile object.
suite()

Define the testing suite for Django’s test runner.

Enables test execution with ./manage.py test <appname>.

Library

class TransManagerMixin

Implement TransManager-type-agnostic browser functionality.

This mixin class provides methods common to all types of TransManager

TransManager backends

class POTManager(full_name, path, source_lang, file_filter)

A browser class for Managing POT files.

Parameter: full_name: Name used for identifying set of msgmerged files related to POT/PO

files found in path.

path: Diretiry base where the POT/PO files can be found. source_language: The code of the source language. Usually it’s English (en). file_filter: Regex for find the POT/PO under path.

calculate_file_stats(filename, try_to_merge)

Return the stats of a specificy file copying it to the static directory.

If try_to_merge is set to True, the stats are calculated after merging the PO file with the related POT.

copy_file_to_static_dir(filename)
Copy a file to the statc msgmerge directory.
delete_file_from_static_dir(filename)
Delete a file from the static cache dir
get_file_contents(filename, is_msgmerged=False, decode=None)

Return the file contents of the requested file.

If is_msgmerged is set to True the merged file stored is opened. If decode is specified the contents are decoded with the decode encoding.

get_file_path(filename, is_msgmerged=False)

Return the full path of the filename.

If is_msgmerged is set to True the path of the merged file is returned.

get_lang_files(lang)
Return a list with the PO filenames for a specificy language.
get_langs()
Return all langs tha have a po file for a object.
get_po_entries(filename)
Return a polib.POFile object with the entries from filename.
get_po_files()
Return a list of PO filenames.
static get_po_stats(po_contents)

Return a dictionary with the stats for a POT/PO file content.

Case the stats for the pofile can not be calculated, the dictionary will be returned with stats equals zero and with the error attribute set as True.

get_source_file_for_pofile(filename)

Find the related source file (POT) for a pofile when it has multiple source files.

This method gets a filename as parameter and tries to discover the related POT file using two methods:

  1. Trying to find a POT file with the same base path that the pofile. Example: /foo/bar.pot and /foo/baz.po match on this method.

  2. Trying to find a POT file with the same domain that the pofile in any directory.

    Example: /foo/bar.pot and /foo/baz/bar.po match on this method. The domain in this case is ‘bar’.

If no POT is found the method returns None.

get_source_files()

Return a list with the source files (pot) paths

Try to find it in the file_set passed to the PO file instace. If it still fails, try to find the POT file in the filesystem.

static get_stats_completion(stats)

Get a dictionary with the translation stats of a pofile and returns the completion of it.

The stats parameter must receive a dictionary like the following: stats = {‘translated’: 50, ‘fuzzy’: 20, ‘untranslated’: 30}

static get_stats_status(stats)

Get a dictionary with the translation stats of a pofile and returns a string with the status in the following format: ‘10 messages complete with 1 fuzzy and 12 untranslated’

The stats parameter must receive a dictionary like the following: stats = {‘translated’: 50, ‘fuzzy’: 20, ‘untranslated’: 30}

guess_language(filename)
Guess a language from the filename.
guess_po_dir()
Guess the po/ diretory to run intltool.
intltool_update()
Create a new POT file using “intltool-update -p” from the source files. Return False if it fails.
static msgfmt_check(po_contents)

Call run_msgfmt_check (runs a msgfmt -c on a file (file object)).

Raise a MsgfmtCheckError in case the stderror has errors or warnings or the command execution returns Error.

msgmerge(pofile, potfile)

Merge two files and save the output at the static diretory.

In case of error, copy the file (pofile) to the destination without merging it.

run_msgfmt_check(po_contents, with_exceptions=True)

Run a msgfmt -c on a file (file object).

Return the output of the execution of the command.

Template Tags

Locks

pofile_lock(context, pofile)
Display a lock with the status of the POFileLock for that POFile.

Statistics

class StatBarsPositions(bar_data, width=100, border=1)

Hold the positions of a number of statistic bars.

Used to present bars for translation completion status.

comp_lang_stats_table(context, stats)
Create a HTML table to present the statistics of all files of a component for a specific language.
comp_stats_table(context, stats)
Create a HTML table to presents the statistics of all languages for a component.
lang_stats_table(context, stats)
Create a HTML table to presents the statistics of all components for a specific language.
number_range(number)

Return a number to group completion stats based on their number.

Depending on the categories defined, different classes will be returned. For example, with the following constant, this will return ‘lt50’ for numbers less than 50 and gt50 for numbers between 50-100. In the case of multiple matches, the first match is returned.

RANGES = {‘lt50’: (0, 49),
‘gt50’: (50, 100)}
pos_from_stat(stat, width, border=1)
Return a StatBarsPositions object for a POFile (stat).
project_stats_table(project)
Create a HTML table to presents the statistics of all Project’s components and langs.
release_stats_table(context, release)
Create a HTML table to presents the statistics of all languages for a specific release.
render_source_files(context, sources)
Create an HTML to present only the source files.
stats_bar_full(stat, width=100)

Create a HTML bar to present the full statistics.

Accepts an optional parameter to specify the width of the total bar.

stats_bar_trans(stat, width=100)

Create an HTML bar to present only the translated statistics.

Accepts an optional parameter to specify the width of the total bar.