convert

Code to convert between different storage formats for localizations.

acesskey

functions used to manipulate access keys in strings.

class translate.convert.accesskey.UnitMixer(labelsuffixes, accesskeysuffixes)

Helper to mix separately defined labels and accesskeys into one unit.

match_entities(index)

Populates mixedentities from the index.

static mix_units(label_unit, accesskey_unit, target_unit)

Mix the given units into the given target_unit if possible.

Might return None if no match is possible.

translate.convert.accesskey.combine(label, accesskey, accesskey_marker='&')

Combine a label and and accesskey to form a label+accesskey string.

We place an accesskey marker before the accesskey in the label and this creates a string with the two combined e.g. “File” + “F” = “&File”

The case of the accesskey is preferred unless no match is found, in which case the alternate case is used.

Parameters:
  • label (unicode) – a label

  • accesskey (unicode char) – The accesskey

Return type:

unicode or None

Returns:

label+accesskey string or None if uncombineable

translate.convert.accesskey.extract(string, accesskey_marker='&')

Extract the label and accesskey from a label+accesskey string.

The function will also try to ignore &entities; which would obviously not contain accesskeys.

Parameters:
  • string (Unicode) – A string that might contain a label with accesskey marker

  • accesskey_marker (Char) – The character that is used to prefix an access key

convert

Handles converting of files between formats (used by translate.convert tools).

class translate.convert.convert.ArchiveConvertOptionParser(formats, usetemplates=False, usepots=False, description=None, archiveformats=None)

ConvertOptionParser that can handle recursing into single archive files.

archiveformats maps extension to class. If the extension doesn’t matter, it can be None.

If the extension is only valid for input/output/template, it can be given as (extension, filepurpose).

add_duplicates_option(default='msgctxt')

Adds an option to say what to do with duplicate strings.

add_fuzzy_option(default=False)

Adds an option to include / exclude fuzzy translations.

add_multifile_option(default='single')

Adds an option to say how to split the po/pot files.

add_option(Option)
add_option(opt_str, ..., kwarg=val, ...) None
add_remove_untranslated_option(default=False)

Adds an option to remove key value from output if it is untranslated.

add_threshold_option(default=None)

Adds an option to output only stores where translation percentage exceeds the threshold.

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)

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

define_option(option)

Defines the given option, replacing an existing one of the same short name if neccessary…

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.

filterinputformats(options)

Filters input formats, processing relevant switches in options.

filteroutputoptions(options)

Filters output options, processing relevant switches in options.

finalizetempoutputfile(options, outputfile, fulloutputpath)

Write the temp outputfile to its final destination.

format_manpage()

Returns a formatted manpage.

getarchiveclass(fileext, filepurpose, isdir=False)

Returns the archiveclass for the given fileext and filepurpose.

getformathelp(formats)

Make a nice help string for describing formats…

getfullinputpath(options, inputpath)

Gets the absolute path to an input file.

getfulloutputpath(options, outputpath)

Gets the absolute path to an output file.

getfulltemplatepath(options, templatepath)

Gets the absolute 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.

isarchive(fileoption, filepurpose='input')

Returns whether the file option is an archive file.

static isexcluded(options, inputpath)

Checks if this path has been excluded.

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)

Makes a subdirectory (recursively if neccessary).

openarchive(archivefilename, filepurpose, **kwargs)

Creates an archive object for the given file.

openinputfile(options, fullinputpath)

Opens the input file.

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.

static potifyformat(fileformat)

Converts a .po to a .pot where required.

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)

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)

Run an individual conversion.

recursearchivefiles(options)

Recurse through archive files and convert files.

recurseinputfilelist(options)

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

recurseinputfiles(options)

Recurse through archive file / directories and return files to be converted.

recursiveprocess(options)

Recurse through directories and convert files.

run(argv=None)

Parses the command line options and runs the conversion.

set_usage(usage=None)

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

seterrorleveloptions()

Sets the errorlevel options.

setformats(formats, usetemplates)

Sets the format options using the given format dictionary.

Parameters:

formats (Dictionary or iterable) –

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

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

setpotoption()

Sets the -P/--pot option depending on input/output formats etc.

setprogressoptions()

Sets the progress options.

settimestampoption()

Sets -S/--timestamp option.

static splitext(pathname)

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

Parameters:

pathname (string) – A file path

Returns:

root, ext

Return type:

tuple

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…

verifyoptions(options)

Verifies that the options are valid (required options are present, etc).

warning(msg, options=None, exc_info=None)

Print a warning message incorporating ‘msg’ to stderr.

class translate.convert.convert.ConvertOptionParser(formats, usetemplates=False, usepots=False, allowmissingtemplate=False, description=None)

A specialized Option Parser for convertor tools…

add_duplicates_option(default='msgctxt')

Adds an option to say what to do with duplicate strings.

add_fuzzy_option(default=False)

Adds an option to include / exclude fuzzy translations.

add_multifile_option(default='single')

Adds an option to say how to split the po/pot files.

add_option(Option)
add_option(opt_str, ..., kwarg=val, ...) None
add_remove_untranslated_option(default=False)

Adds an option to remove key value from output if it is untranslated.

add_threshold_option(default=None)

Adds an option to output only stores where translation percentage exceeds the threshold.

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)

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

define_option(option)

Defines the given option, replacing an existing one of the same short name if neccessary…

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.

filterinputformats(options)

Filters input formats, processing relevant switches in options.

filteroutputoptions(options)

Filters output options, processing relevant switches in options.

finalizetempoutputfile(options, outputfile, fulloutputpath)

Write the temp outputfile to its final destination.

format_manpage()

Returns a formatted manpage.

getformathelp(formats)

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)

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)

Makes a subdirectory (recursively if neccessary).

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.

static potifyformat(fileformat)

Converts a .po to a .pot where required.

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)

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)

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)

Recurse through directories and process files.

run(argv=None)

Parses the command line options and runs the conversion.

set_usage(usage=None)

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

seterrorleveloptions()

Sets the errorlevel options.

setformats(formats, usetemplates)

Sets the format options using the given format dictionary.

Parameters:

formats (Dictionary or iterable) –

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

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

setpotoption()

Sets the -P/--pot option depending on input/output formats etc.

setprogressoptions()

Sets the progress options.

settimestampoption()

Sets -S/--timestamp option.

static splitext(pathname)

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

Parameters:

pathname (string) – A file path

Returns:

root, ext

Return type:

tuple

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…

verifyoptions(options)

Verifies that the options are valid (required options are present, etc).

warning(msg, options=None, exc_info=None)

Print a warning message incorporating ‘msg’ to stderr.

class translate.convert.convert.Replacer(searchstring, replacestring)

An object that knows how to replace strings in files.

doreplace(text)

Actually replace the text.

searchreplaceinput(inputfile, outputfile, templatefile, **kwargs)

Copies the input file to the output file, searching and replacing.

searchreplacetemplate(inputfile, outputfile, templatefile, **kwargs)

Copies the template file to the output file, searching and replacing.

translate.convert.convert.copyinput(inputfile, outputfile, templatefile, **kwargs)

Copies the input file to the output file.

translate.convert.convert.copytemplate(inputfile, outputfile, templatefile, **kwargs)

Copies the template file to the output file.

translate.convert.convert.should_output_store(store, threshold)

Check if the percent of translated source words more than or equal to the given threshold.

csv2po

csv2tbx

Convert Comma-Separated Value (.csv) files to a TermBase eXchange (.tbx) glossary file.

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

translate.convert.csv2tbx.convertcsv(inputfile, outputfile, templatefile, charset=None, columnorder=None)

reads in inputfile using csvl10n, converts using csv2tbx, writes to outputfile.

class translate.convert.csv2tbx.csv2tbx(charset=None)

a class that takes translations from a .csv file and puts them in a .tbx file.

convertfile(csvfile)

converts a csvfile to a tbxfile, and returns it. uses templatepo if given at construction.

dtd2po

factory

Factory methods to convert supported input files to supported translatable files.

exception translate.convert.factory.UnknownExtensionError(afile)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception translate.convert.factory.UnsupportedConversionError(in_ext=None, out_ext=None, templ_ext=None)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

html2po

ical2po

ini2po

json2po

moz2po

mozfunny2prop

mozlang2po

odf2xliff

Convert OpenDocument (ODF) files to XLIFF localization files.

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

translate.convert.odf2xliff.convertodf(inputfile, outputfile, templates)

Convert an ODF package to XLIFF.

oo2po

oo2xliff

Convert an OpenOffice.org (SDF) localization file to XLIFF localization files.

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

translate.convert.oo2xliff.convertoo(inputfile, outputfile, templates, pot=False, sourcelanguage=None, targetlanguage=None, duplicatestyle='msgctxt', multifilestyle='single')

Reads in stdin using inputstore class, converts using convertorclass, writes to stdout.

translate.convert.oo2xliff.verifyoptions(options)

Verifies the commandline options.

php2po

po2csv

po2dtd

po2html

po2ical

po2ini

po2json

Convert Gettext PO localization files to JSON files.

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

po2mozlang

po2moz

po2oo

Convert Gettext PO localization files to an OpenOffice.org (SDF) localization file.

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

po2php

po2prop

po2rc

po2resx

Convert Gettext PO localisation files to .Net Resource (.resx) files.

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

po2sub

po2symb

po2tiki

po2tmx

po2ts

po2txt

Convert Gettext PO localization files to plain text (.txt) files.

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

class translate.convert.po2txt.po2txt(input_file, output_file, template_file=None, include_fuzzy=False, output_threshold=None, encoding='utf-8', wrap=None)

po2txt can take a po file and generate txt.

best to give it a template file otherwise will just concat msgstrs

convert_store()

Convert a source file to a target file.

merge_stores()

Convert a source file to a target file using a template file.

Source file is in source format, while target and template files use target format.

run()

Run the converter.

wrapmessage(message)

Rewraps text as required.

translate.convert.po2txt.run_converter(inputfile, outputfile, templatefile=None, wrap=None, includefuzzy=False, encoding='utf-8', outputthreshold=None)

Wrapper around converter.

po2web2py

Convert GNU/gettext PO files to web2py translation dictionaries (.py).

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

po2wordfast

po2xliff

po2yaml

pot2po

prop2mozfunny

prop2po

rc2po

resx2po

sub2po

symb2po

tiki2po

ts2po

txt2po

web2py2po

xliff2odf

Convert XLIFF translation files to OpenDocument (ODF) files.

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

translate.convert.xliff2odf.convertxliff(input_file, output_file, template)

Create a translated ODF using an ODF template and a XLIFF file.

translate.convert.xliff2odf.write_odf(template, output_file, dom_trees)

Write the translated ODF package.

The resulting ODF package is a copy of the template ODF package, with the translatable files replaced by their translated versions.

xliff2oo

Convert XLIFF localization files to an OpenOffice.org (SDF) localization file.

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

xliff2po

yaml2po