tools¶
Code to perform various operations, mostly on po files.
phppo2pypo¶
poclean¶
pocompile¶
poconflicts¶
pocount¶
podebug¶
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.
- 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¶
porestructure¶
posegment¶
poswap¶
poterminology¶
pretranslate¶
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.