tools¶
Code to perform various operations, mostly on po files.
phppo2pypo¶
Convert PHP format .po files to Python format .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.
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.
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, ...)
- 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 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.
- getmissingtemplatename(inputname)¶
Gets the relative template path expected for an input 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 isrecursive(fileoption, filepurpose='input')¶
Checks if fileoption is a recursive file.
- isvalidinputname(inputname)¶
Checks if this is a valid input filename.
- static normalizerelativepath(pathname, allow_empty: bool = False)¶
Normalizes a recursive relative path and rejects path traversal.
- 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_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.
- 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.
- set_usage(usage=None) None¶
Sets the usage string - if usage not given, uses getusagestring for each option.
- 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.
- 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)
- class translate.tools.pocount.StatsDict¶
- clear()¶
Remove all items from the dict.
- copy()¶
Return a shallow copy of the dict.
- classmethod fromkeys(iterable, value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- items()¶
Return a set-like object providing a view on the dict’s items.
- keys()¶
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.¶
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()¶
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.¶
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()¶
Return an object providing a view on the dict’s values.
- 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.
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, ...)
- 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 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.
- getmissingtemplatename(inputname)¶
Gets the relative template path expected for an input 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 isrecursive(fileoption, filepurpose='input')¶
Checks if fileoption is a recursive file.
- isvalidinputname(inputname)¶
Checks if this is a valid input filename.
- static normalizerelativepath(pathname, allow_empty: bool = False)¶
Normalizes a recursive relative path and rejects path traversal.
- 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_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.
- set_usage(usage=None) None¶
Sets the usage string - if usage not given, uses getusagestring for each option.
- 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.
- 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.
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.
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, ...)
- 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 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.
- getmissingtemplatename(inputname)¶
Gets the relative template path expected for an input 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 isrecursive(fileoption, filepurpose='input')¶
Checks if fileoption is a recursive file.
- isvalidinputname(inputname)¶
Checks if this is a valid input filename.
- static normalizerelativepath(pathname, allow_empty: bool = False)¶
Normalizes a recursive relative path and rejects path traversal.
- 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_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.
- 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.
- set_usage(usage=None) None¶
Sets the usage string - if usage not given, uses getusagestring for each option.
- 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.
- 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.
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.
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, ...)
- 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 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.
- getmissingtemplatename(inputname)¶
Gets the relative template path expected for an input 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 isrecursive(fileoption, filepurpose='input')¶
Checks if fileoption is a recursive file.
- isvalidinputname(inputname)¶
Checks if this is a valid input filename.
- static normalizerelativepath(pathname, allow_empty: bool = False)¶
Normalizes a recursive relative path and rejects path traversal.
- 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_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.
- set_usage(usage=None) None¶
Sets the usage string - if usage not given, uses getusagestring for each option.
- 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.
- 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.
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
matcherobjects.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.
- 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.
pypo2phppo¶
Convert Python format .po files to PHP format .po files.