tools

Code to perform various operations, mostly on po files.

build_tmdb

Import units from translations files into tmdb.

phppo2pypo

Convert PHP format .po files to Python format .po files.

translate.tools.phppo2pypo.convertphp2py(inputfile, outputfile, template=None) bool

Converts from PHP .po format to Python .po format.

Parameters:
  • inputfile -- file handle of the source

  • outputfile -- file handle to write to

  • template -- unused

translate.tools.phppo2pypo.main(argv=None) None

Converts PHP .po files to Python .po files.

poclean

Produces a clean file from an unclean file (Trados/Wordfast) by stripping out the tw4win indicators.

This does not convert an RTF file to PO/XLIFF, but produces the target file with only the target text in from a text version of the RTF.

translate.tools.poclean.cleanfile(thefile)

Cleans the given file.

translate.tools.poclean.cleanunit(unit) None

Cleans the targets in the given unit.

translate.tools.poclean.runclean(inputfile, outputfile, templatefile) bool

Reads in inputfile, cleans, writes to outputfile.

pocompile

Compile XLIFF and Gettext PO localization files into Gettext MO (Machine Object) files.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pocompile.html for examples and usage instructions.

translate.tools.pocompile.convertmo(inputfile, outputfile, templatefile, includefuzzy=False) int

Reads in a base class derived inputfile, converts using pocompile, writes to outputfile.

poconflicts

Conflict finder for Gettext PO localization files.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/poconflicts.html for examples and usage instructions.

class translate.tools.poconflicts.ConflictOptionParser(formats: dict, usetemplates: bool = False, allowmissingtemplate: bool = False, description: str | None = None)

a specialized Option Parser for the conflict tool...

add_option(Option)
add_option(opt_str, ..., kwarg=val, ...) None
buildconflictmap() None

Work out which strings are conflicting.

check_values(values: Values, args: [string])

-> (values : Values, args : [string])

Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.

checkoutputsubdir(options, subdir) None

Checks to see if subdir under options.output needs to be created, creates if necessary.

static clean(string, options)

Returns the cleaned string that contains the text to be matched.

define_option(option) None

Defines the given option, replacing an existing one of the same short name if necessary...

destroy()

Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable.

disable_interspersed_args()

Set parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don't get confused.

enable_interspersed_args()

Set parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.

error(msg: string)

Print a usage message incorporating 'msg' to stderr and exit. If you override this in a subclass, it should not return -- it should either exit or raise an exception.

finalizetempoutputfile(options, outputfile, fulloutputpath) None

Write the temp outputfile to its final destination.

static flatten(text, joinchar)

Flattens text to just be words.

format_manpage()

Returns a formatted manpage.

static getformathelp(formats) str

Make a nice help string for describing formats...

static getfullinputpath(options, inputpath)

Gets the full path to an input file.

static getfulloutputpath(options, outputpath)

Gets the full path to an output file.

getfulltemplatepath(options, templatepath)

Gets the full path to a template file.

getoutputname(options, inputname, outputformat)

Gets an output filename based on the input filename.

getoutputoptions(options, inputpath, templatepath)

Works out which output format and processor method to use...

getpassthroughoptions(options)

Get the options required to pass to the filtermethod...

gettemplatename(options, inputname)

Gets an output filename based on the input filename.

static getusageman(option)

Returns the usage string for the given option.

static getusagestring(option)

Returns the usage string for the given option.

static isexcluded(options, inputpath) bool

Checks if this path has been excluded.

static isrecursive(fileoption, filepurpose='input')

Checks if fileoption is a recursive file.

isvalidinputname(inputname)

Checks if this is a valid input filename.

static mkdir(parent, subdir) None

Makes a subdirectory (recursively if necessary).

static openinputfile(options, fullinputpath)

Opens the input file.

static openoutputfile(options, fulloutputpath)

Opens the output file.

opentemplatefile(options, fulltemplatepath)

Opens the template file (if required).

static opentempoutputfile(options, fulloutputpath)

Opens a temporary output file.

outputconflicts(options) None

Saves the result of the conflict match.

parse_args(args=None, values=None)

Parses the command line options, handling implicit input/output args.

print_help(file: file = stdout)

Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).

print_manpage(file=None) None

Outputs a manpage for the program using the help information.

print_usage(file: file = stdout)

Print the usage message for the current program (self.usage) to 'file' (default stdout). Any occurrence of the string "%prog" in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined.

print_version(file: file = stdout)

Print the version message for this program (self.version) to 'file' (default stdout). As with print_usage(), any occurrence of "%prog" in self.version is replaced by the current program's name. Does nothing if self.version is empty or undefined.

processfile(fileprocessor, options, fullinputpath) bool

Process an individual file.

recurseinputfilelist(options)

Use a list of files, and find a common base directory for them.

recurseinputfiles(options)

Recurse through directories and return files to be processed.

recursiveprocess(options) None

Recurse through directories and process files.

run() None

Parses the arguments, and runs recursiveprocess with the resulting options...

set_usage(usage=None) None

Sets the usage string - if usage not given, uses getusagestring for each option.

seterrorleveloptions() None

Sets the errorlevel options.

setformats(formats, usetemplates) None

Sets the formats and customizes the input/output option help text.

setmanpageoption() None

Creates a manpage option that allows the optionparser to generate a manpage.

setprogressoptions() None

Sets the progress options.

static splitext(pathname: str) tuple[str, str]

Splits pathname into name and ext, and removes the extsep.

Parameters:

pathname -- A file path

Returns:

root, ext

splitinputext(inputpath)

Splits an inputpath into name and extension.

splittemplateext(templatepath)

Splits a templatepath into name and extension.

templateexists(options, templatepath)

Returns whether the given template exists...

warning(msg, options=None, exc_info: tuple[type[BaseException], BaseException, TracebackType] | tuple[None, None, None] | None = None) None

Print a warning message incorporating 'msg' to stderr.

pocount

Count strings and words for supported localization files.

These include: XLIFF, TMX, Gettex PO and MO, Qt .ts and .qm, Wordfast TM, etc

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pocount.html for examples and usage instructions.

class translate.tools.pocount.ConsoleColor

Class to implement color mode.

class translate.tools.pocount.CsvRenderer(stats: 'StatCollector')
class translate.tools.pocount.FullRenderer(stats: StatCollector)
class translate.tools.pocount.Renderer(stats: 'StatCollector')
class translate.tools.pocount.ShortStringsRenderer(stats: StatCollector, indent: int = 8)
Parameters:

indent -- indentation of the 2nd column (length of longest filename)

class translate.tools.pocount.ShortWordsRenderer(stats: StatCollector, indent: int = 8)
Parameters:

indent -- indentation of the 2nd column (length of longest filename)

translate.tools.pocount.wordsinunit(unit)

Counts the words in the unit's source and target, taking plurals into account. The target words are only counted if the unit is translated.

podebug

Insert debug messages into XLIFF and Gettext PO localization files.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/podebug.html for examples and usage instructions.

translate.tools.podebug.convertpo(inputfile, outputfile, templatefile, format=None, rewritestyle=None, ignoreoption=None, preserveplaceholders=None) int

Reads in inputfile, changes it to have debug strings, writes to outputfile.

pogrep

Grep XLIFF, Gettext PO and TMX localization files.

Matches are output to snippet files of the same type which can then be reviewed and later merged using pomerge.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pogrep.html for examples and usage instructions.

class translate.tools.pogrep.GrepMatch(unit, part='target', part_n=0, start=0, end=0)

Just a small data structure that represents a search match.

class translate.tools.pogrep.GrepOptionParser(formats: dict, usetemplates: bool = False, allowmissingtemplate: bool = False, description: str | None = None)

a specialized Option Parser for the grep tool...

add_option(Option)
add_option(opt_str, ..., kwarg=val, ...) None
check_values(values: Values, args: [string])

-> (values : Values, args : [string])

Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.

checkoutputsubdir(options, subdir) None

Checks to see if subdir under options.output needs to be created, creates if necessary.

define_option(option) None

Defines the given option, replacing an existing one of the same short name if necessary...

destroy()

Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable.

disable_interspersed_args()

Set parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don't get confused.

enable_interspersed_args()

Set parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.

error(msg: string)

Print a usage message incorporating 'msg' to stderr and exit. If you override this in a subclass, it should not return -- it should either exit or raise an exception.

finalizetempoutputfile(options, outputfile, fulloutputpath) None

Write the temp outputfile to its final destination.

format_manpage()

Returns a formatted manpage.

static getformathelp(formats) str

Make a nice help string for describing formats...

static getfullinputpath(options, inputpath)

Gets the full path to an input file.

static getfulloutputpath(options, outputpath)

Gets the full path to an output file.

getfulltemplatepath(options, templatepath)

Gets the full path to a template file.

getoutputname(options, inputname, outputformat)

Gets an output filename based on the input filename.

getoutputoptions(options, inputpath, templatepath)

Works out which output format and processor method to use...

getpassthroughoptions(options)

Get the options required to pass to the filtermethod...

gettemplatename(options, inputname)

Gets an output filename based on the input filename.

static getusageman(option)

Returns the usage string for the given option.

static getusagestring(option)

Returns the usage string for the given option.

static isexcluded(options, inputpath) bool

Checks if this path has been excluded.

static isrecursive(fileoption, filepurpose='input')

Checks if fileoption is a recursive file.

isvalidinputname(inputname)

Checks if this is a valid input filename.

static mkdir(parent, subdir) None

Makes a subdirectory (recursively if necessary).

static openinputfile(options, fullinputpath)

Opens the input file.

static openoutputfile(options, fulloutputpath)

Opens the output file.

opentemplatefile(options, fulltemplatepath)

Opens the template file (if required).

static opentempoutputfile(options, fulloutputpath)

Opens a temporary output file.

parse_args(args=None, values=None)

Parses the command line options, handling implicit input/output args.

print_help(file: file = stdout)

Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).

print_manpage(file=None) None

Outputs a manpage for the program using the help information.

print_usage(file: file = stdout)

Print the usage message for the current program (self.usage) to 'file' (default stdout). Any occurrence of the string "%prog" in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined.

print_version(file: file = stdout)

Print the version message for this program (self.version) to 'file' (default stdout). As with print_usage(), any occurrence of "%prog" in self.version is replaced by the current program's name. Does nothing if self.version is empty or undefined.

processfile(fileprocessor, options, fullinputpath, fulloutputpath, fulltemplatepath) bool

Process an individual file.

recurseinputfilelist(options)

Use a list of files, and find a common base directory for them.

recurseinputfiles(options)

Recurse through directories and return files to be processed.

recursiveprocess(options) None

Recurse through directories and process files.

run() None

Parses the arguments, and runs recursiveprocess with the resulting options.

set_usage(usage=None) None

Sets the usage string - if usage not given, uses getusagestring for each option.

seterrorleveloptions() None

Sets the errorlevel options.

setformats(formats: dict | list[tuple[Any, Any]], usetemplates: bool) None

Sets the format options using the given format dictionary.

Parameters:

formats --

The dictionary keys should be:

  • Single strings (or 1-tuples) containing an input format (if not usetemplates)

  • Tuples containing an input format and template format (if usetemplates)

  • Formats can be None to indicate what to do with standard input

The dictionary values should be tuples of outputformat (string) and processor method.

setmanpageoption() None

Creates a manpage option that allows the optionparser to generate a manpage.

setprogressoptions() None

Sets the progress options.

static splitext(pathname: str) tuple[str, str]

Splits pathname into name and ext, and removes the extsep.

Parameters:

pathname -- A file path

Returns:

root, ext

splitinputext(inputpath)

Splits an inputpath into name and extension.

splittemplateext(templatepath)

Splits a templatepath into name and extension.

templateexists(options, templatepath)

Returns whether the given template exists...

warning(msg, options=None, exc_info: tuple[type[BaseException], BaseException, TracebackType] | tuple[None, None, None] | None = None) None

Print a warning message incorporating 'msg' to stderr.

translate.tools.pogrep.find_matches(unit, part, strings, re_search)

Return the GrepFilter objects where re_search matches in strings.

translate.tools.pogrep.real_index(string, nfc_index)

Calculate the real index in the unnormalized string that corresponds to the index nfc_index in the normalized string.

translate.tools.pogrep.rungrep(inputfile, outputfile, templatefile, checkfilter) bool

Reads in inputfile, filters using checkfilter, writes to outputfile.

pomerge

Merges XLIFF and Gettext PO localization files.

Snippet file produced by e.g. pogrep and updated by a translator can be merged back into the original files.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pomerge.html for examples and usage instructions.

translate.tools.pomerge.mergestores(store1, store2, mergeblanks, mergefuzzy, mergecomments)

Take any new translations in store2 and write them into store1.

translate.tools.pomerge.str2bool(option: str) bool

Convert a string value to boolean.

Parameters:

option -- yes, true, 1, no, false, 0

porestructure

Restructure Gettxt PO files produced by poconflicts into the original directory tree for merging using pomerge.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pomerge.html for examples and usage instructions.

class translate.tools.porestructure.SplitOptionParser(formats: dict, usetemplates: bool = False, allowmissingtemplate: bool = False, description: str | None = None)

a specialized Option Parser for posplit.

add_option(Option)
add_option(opt_str, ..., kwarg=val, ...) None
check_values(values: Values, args: [string])

-> (values : Values, args : [string])

Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.

checkoutputsubdir(options, subdir) None

Checks to see if subdir under options.output needs to be created, creates if necessary.

define_option(option) None

Defines the given option, replacing an existing one of the same short name if necessary...

destroy()

Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable.

disable_interspersed_args()

Set parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don't get confused.

enable_interspersed_args()

Set parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.

error(msg: string)

Print a usage message incorporating 'msg' to stderr and exit. If you override this in a subclass, it should not return -- it should either exit or raise an exception.

finalizetempoutputfile(options, outputfile, fulloutputpath) None

Write the temp outputfile to its final destination.

format_manpage()

Returns a formatted manpage.

static getformathelp(formats) str

Make a nice help string for describing formats...

static getfullinputpath(options, inputpath)

Gets the full path to an input file.

static getfulloutputpath(options, outputpath)

Gets the full path to an output file.

getfulltemplatepath(options, templatepath)

Gets the full path to a template file.

getoutputname(options, inputname, outputformat)

Gets an output filename based on the input filename.

getoutputoptions(options, inputpath, templatepath)

Works out which output format and processor method to use...

getpassthroughoptions(options)

Get the options required to pass to the filtermethod...

gettemplatename(options, inputname)

Gets an output filename based on the input filename.

static getusageman(option)

Returns the usage string for the given option.

static getusagestring(option)

Returns the usage string for the given option.

static isexcluded(options, inputpath) bool

Checks if this path has been excluded.

static isrecursive(fileoption, filepurpose='input')

Checks if fileoption is a recursive file.

isvalidinputname(inputname)

Checks if this is a valid input filename.

static mkdir(parent, subdir) None

Makes a subdirectory (recursively if necessary).

static openinputfile(options, fullinputpath)

Opens the input file.

static openoutputfile(options, fulloutputpath)

Opens the output file.

opentemplatefile(options, fulltemplatepath)

Opens the template file (if required).

static opentempoutputfile(options, fulloutputpath)

Opens a temporary output file.

parse_args(args=None, values=None)

Parses the command line options, handling implicit input/output args.

print_help(file: file = stdout)

Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).

print_manpage(file=None) None

Outputs a manpage for the program using the help information.

print_usage(file: file = stdout)

Print the usage message for the current program (self.usage) to 'file' (default stdout). Any occurrence of the string "%prog" in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined.

print_version(file: file = stdout)

Print the version message for this program (self.version) to 'file' (default stdout). As with print_usage(), any occurrence of "%prog" in self.version is replaced by the current program's name. Does nothing if self.version is empty or undefined.

processfile(options, fullinputpath) bool

Process an individual file.

recurseinputfilelist(options)

Use a list of files, and find a common base directory for them.

recurseinputfiles(options)

Recurse through directories and return files to be processed.

recursiveprocess(options) None

Recurse through directories and process files.

run() None

Parses the arguments, and runs recursiveprocess with the resulting options...

set_usage(usage=None) None

Sets the usage string - if usage not given, uses getusagestring for each option.

seterrorleveloptions() None

Sets the errorlevel options.

setformats(formats: dict | list[tuple[Any, Any]], usetemplates: bool) None

Sets the format options using the given format dictionary.

Parameters:

formats --

The dictionary keys should be:

  • Single strings (or 1-tuples) containing an input format (if not usetemplates)

  • Tuples containing an input format and template format (if usetemplates)

  • Formats can be None to indicate what to do with standard input

The dictionary values should be tuples of outputformat (string) and processor method.

setmanpageoption() None

Creates a manpage option that allows the optionparser to generate a manpage.

setprogressoptions() None

Sets the progress options.

static splitext(pathname: str) tuple[str, str]

Splits pathname into name and ext, and removes the extsep.

Parameters:

pathname -- A file path

Returns:

root, ext

splitinputext(inputpath)

Splits an inputpath into name and extension.

splittemplateext(templatepath)

Splits a templatepath into name and extension.

templateexists(options, templatepath)

Returns whether the given template exists...

warning(msg, options=None, exc_info: tuple[type[BaseException], BaseException, TracebackType] | tuple[None, None, None] | None = None) None

Print a warning message incorporating 'msg' to stderr.

posegment

Segment Gettext PO, XLIFF and TMX localization files at the sentence level.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/posegment.html for examples and usage instructions.

translate.tools.posegment.segmentfile(inputfile, outputfile, templatefile, sourcelanguage='en', targetlanguage=None, stripspaces=True, onlyaligned=False) int

Reads in inputfile, segments it then, writes to outputfile.

poswap

Builds a new translation file with the target of the input language as source language.

Note

Ensure that the two po files correspond 100% to the same pot file before using this.

To translate Kurdish (ku) through French:

poswap -i fr/ -t ku -o fr-ku

To convert the fr-ku files back to en-ku:

poswap --reverse -i fr/ -t fr-ku -o en-ku

To translate Quechua (qu) through Spanish (es) using intermediate mode:

poswap --intermediate -t en/ es/ es-qu/

Intermediate mode keeps the original source language (English) and adds the intermediate language translation (Spanish) as a translator comment, making it easier to translate through an intermediate language while keeping both languages visible.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/poswap.html for examples and usage instructions.

translate.tools.poswap.add_missing_translation_note(unit, inputpo) None

Add a note indicating no translation was found.

translate.tools.poswap.convertpo(inputpofile, outputpotfile, template, reverse=False, intermediate=False) int

Reads in inputpofile, removes the header, writes to outputpotfile.

translate.tools.poswap.swapdir(store) None

Swap the source and target of each unit.

poterminology

Create a terminology file by reading a set of .po or .pot files to produce a pootle-terminology.pot.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/poterminology.html for examples and usage instructions.

class translate.tools.poterminology.TerminologyOptionParser(formats: dict, usetemplates: bool = False, allowmissingtemplate: bool = False, description: str | None = None)

a specialized Option Parser for the terminology tool...

add_option(Option)
add_option(opt_str, ..., kwarg=val, ...) None
check_values(values: Values, args: [string])

-> (values : Values, args : [string])

Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.

checkoutputsubdir(options, subdir) None

Checks to see if subdir under options.output needs to be created, creates if necessary.

define_option(option) None

Defines the given option, replacing an existing one of the same short name if necessary...

destroy()

Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable.

disable_interspersed_args()

Set parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don't get confused.

enable_interspersed_args()

Set parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.

error(msg: string)

Print a usage message incorporating 'msg' to stderr and exit. If you override this in a subclass, it should not return -- it should either exit or raise an exception.

finalizetempoutputfile(options, outputfile, fulloutputpath) None

Write the temp outputfile to its final destination.

format_manpage()

Returns a formatted manpage.

static getformathelp(formats) str

Make a nice help string for describing formats...

static getfullinputpath(options, inputpath)

Gets the full path to an input file.

static getfulloutputpath(options, outputpath)

Gets the full path to an output file.

getfulltemplatepath(options, templatepath)

Gets the full path to a template file.

getoutputname(options, inputname, outputformat)

Gets an output filename based on the input filename.

getoutputoptions(options, inputpath, templatepath)

Works out which output format and processor method to use...

getpassthroughoptions(options)

Get the options required to pass to the filtermethod...

gettemplatename(options, inputname)

Gets an output filename based on the input filename.

static getusageman(option)

Returns the usage string for the given option.

static getusagestring(option)

Returns the usage string for the given option.

static isexcluded(options, inputpath) bool

Checks if this path has been excluded.

static isrecursive(fileoption, filepurpose='input')

Checks if fileoption is a recursive file.

isvalidinputname(inputname)

Checks if this is a valid input filename.

static mkdir(parent, subdir) None

Makes a subdirectory (recursively if necessary).

static openinputfile(options, fullinputpath)

Opens the input file.

static openoutputfile(options, fulloutputpath)

Opens the output file.

opentemplatefile(options, fulltemplatepath)

Opens the template file (if required).

static opentempoutputfile(options, fulloutputpath)

Opens a temporary output file.

outputterminology(options) None

Saves the generated terminology glossary.

parse_args(args=None, values=None)

Parses the command line options, handling implicit input/output args.

print_help(file: file = stdout)

Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).

print_manpage(file=None) None

Outputs a manpage for the program using the help information.

print_usage(file: file = stdout)

Print the usage message for the current program (self.usage) to 'file' (default stdout). Any occurrence of the string "%prog" in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined.

print_version(file: file = stdout)

Print the version message for this program (self.version) to 'file' (default stdout). As with print_usage(), any occurrence of "%prog" in self.version is replaced by the current program's name. Does nothing if self.version is empty or undefined.

processfile(fileprocessor, options, fullinputpath) None

Process an individual file.

recurseinputfilelist(options)

Use a list of files, and find a common base directory for them.

recurseinputfiles(options)

Recurse through directories and return files to be processed.

recursiveprocess(options) None

Recurse through directories and process files.

run() None

Parses the arguments, and runs recursiveprocess with the resulting options.

set_usage(usage=None) None

Sets the usage string - if usage not given, uses getusagestring for each option.

seterrorleveloptions() None

Sets the errorlevel options.

setformats(formats: dict | list[tuple[Any, Any]], usetemplates: bool) None

Sets the format options using the given format dictionary.

Parameters:

formats --

The dictionary keys should be:

  • Single strings (or 1-tuples) containing an input format (if not usetemplates)

  • Tuples containing an input format and template format (if usetemplates)

  • Formats can be None to indicate what to do with standard input

The dictionary values should be tuples of outputformat (string) and processor method.

setmanpageoption() None

Creates a manpage option that allows the optionparser to generate a manpage.

setprogressoptions() None

Sets the progress options.

static splitext(pathname: str) tuple[str, str]

Splits pathname into name and ext, and removes the extsep.

Parameters:

pathname -- A file path

Returns:

root, ext

splitinputext(inputpath)

Splits an inputpath into name and extension.

splittemplateext(templatepath)

Splits a templatepath into name and extension.

templateexists(options, templatepath)

Returns whether the given template exists...

warning(msg, options=None, exc_info: tuple[type[BaseException], BaseException, TracebackType] | tuple[None, None, None] | None = None) None

Print a warning message incorporating 'msg' to stderr.

class translate.tools.poterminology.UnitInfo(source, target, locations, sourcenotes, transnotes)
count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

locations: frozenset

Alias for field number 2

source: str

Alias for field number 0

sourcenotes: frozenset

Alias for field number 3

target: str

Alias for field number 1

transnotes: frozenset

Alias for field number 4

pretranslate

Fill localization files with suggested translations based on translation memory and existing translations.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pretranslate.html for examples and usage instructions.

translate.tools.pretranslate.match_fuzzy(input_unit, matchers)

Return a fuzzy match from a queue of matchers.

translate.tools.pretranslate.match_source(input_unit, template_store)

Returns a matching unit from a template. matching based on unit id.

translate.tools.pretranslate.match_template_id(input_unit, template_store)

Returns a matching unit from a template. matching based on unit id.

translate.tools.pretranslate.match_template_location(input_unit, template_store)

Returns a matching unit from a template. matching based on locations.

translate.tools.pretranslate.memory(tmfiles, max_candidates=1, min_similarity=75, max_length=1000)

Returns the TM store to use. Only initialises on first call.

translate.tools.pretranslate.pretranslate_file(input_file, output_file, template_file, tm=None, min_similarity=75, fuzzymatching=True) int

Pretranslate any factory supported file with old translations and translation memory.

translate.tools.pretranslate.pretranslate_store(input_store, template_store, tm=None, min_similarity=75, fuzzymatching=True)

Do the actual pretranslation of a whole store.

translate.tools.pretranslate.pretranslate_unit(input_unit, template_store, matchers=None, mark_reused=False, merge_on='id')

Pretranslate a unit or return unchanged if no translation was found.

Parameters:
  • input_unit -- Unit that will be pretranslated.

  • template_store -- Fill input unit with units matching in this store.

  • matchers -- List of fuzzy matcher objects.

  • mark_reused -- Whether to mark old translations as reused or not.

  • merge_on -- Where will the merge matching happen on.

pydiff

diff tool like GNU diff, but lets you have special options that are useful in dealing with PO files.

class translate.tools.pydiff.DirDiffer(fromdir, todir, options)

generates diffs between directories.

isexcluded(difffile)

Checks if the given filename has been excluded from the diff.

writediff(outfile) None

Writes the actual diff to the given file.

class translate.tools.pydiff.FileDiffer(fromfile, tofile, options)

generates diffs between files.

get_from_lines(group)

Returns the lines referred to by group, from the fromfile.

get_to_lines(group)

Returns the lines referred to by group, from the tofile.

unified_diff(group)

Takes the group of opcodes and generates a unified diff line by line.

writediff(outfile) None

Writes the actual diff to the given file.

translate.tools.pydiff.main() None

Main program for pydiff.

pypo2phppo

Convert Python format .po files to PHP format .po files.

translate.tools.pypo2phppo.convertpy2php(inputfile, outputfile, template=None) bool

Converts from Python .po to PHP .po.

Parameters:
  • inputfile -- file handle of the source

  • outputfile -- file handle to write to

  • template -- unused

translate.tools.pypo2phppo.main(argv=None) None

Converts from Python .po to PHP .po.