filters

Filters that can be used on translations…

autocorrect

A set of autocorrect functions that fix common punctuation and space problems automatically.

translate.filters.autocorrect.correct(source, target)

Runs a set of easy and automatic corrections.

Current corrections include:
  • Ellipses - align target to use source form of ellipses (either three dots or the Unicode ellipses characters)

  • Missing whitespace and start or end of the target

  • Missing punction (.:?) at the end of the target

checks

decoration

functions to get decorative/informative text out of strings…

translate.filters.decoration.countaccelerators(accelmarker, acceptlist=None)

Returns a function that counts the number of accelerators marked with the given marker.

translate.filters.decoration.findaccelerators(str1, accelmarker, acceptlist=None)

Returns all the accelerators and locations in str1 marked with a given marker.

translate.filters.decoration.findmarkedvariables(str1, startmarker, endmarker, ignorelist=[])

Returns all the variables and locations in str1 marked with a given marker.

translate.filters.decoration.getaccelerators(accelmarker, acceptlist=None)

Returns a function that gets a list of accelerators marked using accelmarker.

translate.filters.decoration.getemails(str1)

Returns the email addresses that are in a string.

translate.filters.decoration.getfunctions(str1)

Returns the functions() that are in a string, while ignoring the trailing punctuation in the given parameter.

translate.filters.decoration.getnumbers(str1)

Returns any numbers that are in the string.

translate.filters.decoration.geturls(str1)

Returns the URIs in a string.

translate.filters.decoration.getvariables(startmarker, endmarker)

Returns a function that gets a list of variables marked using startmarker and endmarker.

translate.filters.decoration.ispurepunctuation(str1)

Checks whether the string is entirely punctuation.

translate.filters.decoration.isvalidaccelerator(accelerator: str, acceptlist: str | None = None) bool

Returns whether the given accelerator character is valid.

Parameters:
  • accelerator – A character to be checked for accelerator validity

  • acceptlist – A list of characters that are permissible as accelerators

Returns:

True if the supplied character is an acceptable accelerator

translate.filters.decoration.puncend(str1, punctuation)

Returns all the punctuation from the end of the string.

translate.filters.decoration.puncstart(str1, punctuation)

Returns all the punctuation from the start of the string.

translate.filters.decoration.spaceend(str1)

Returns all the whitespace from the end of the string.

translate.filters.decoration.spacestart(str1)

Returns all the whitespace from the start of the string.

helpers

a set of helper functions for filters…

translate.filters.helpers.countmatch(str1, str2, countstr)

Checks whether countstr occurs the same number of times in str1 and str2.

translate.filters.helpers.countsmatch(str1, str2, countlist)

Checks whether each element in countlist occurs the same number of times in str1 and str2.

translate.filters.helpers.filtercount(str1, func)

Returns the number of characters in str1 that pass func.

translate.filters.helpers.filtertestmethod(testmethod, strfilter)

Returns a version of the testmethod that operates on filtered strings using strfilter.

translate.filters.helpers.funcmatch(str1, str2, func, *args)

Returns whether the result of func is the same for str1 and str2.

translate.filters.helpers.funcsmatch(str1, str2, funclist)

Checks whether the results of each func in funclist match for str1 and str2.

translate.filters.helpers.multifilter(str1, strfilters, *args)

Passes str1 through a list of filters.

translate.filters.helpers.multifiltertestmethod(testmethod, strfilters)

Returns a version of the testmethod that operates on filtered strings using strfilter.

pofilter

prefilters

Filters that strings can be passed through before certain tests.

translate.filters.prefilters.filteraccelerators(accelmarker: str | None) Callable

Returns a function that filters accelerators marked using accelmarker from a strings.

Parameters:

accelmarker – Accelerator marker character

Returns:

fn(str1, acceplist=None)

translate.filters.prefilters.filtervariables(startmarker: str | None, endmarker: str | None, varfilter: Callable) Callable

Returns a function that filters variables marked using startmarker and endmarker from a string.

Parameters:
  • startmarker – Start of variable marker

  • endmarker – End of variable marker

  • varfilter – fn(variable, startmarker, endmarker)

Returns:

fn(str1)

translate.filters.prefilters.filterwordswithpunctuation(str1)

Goes through a list of known words that have punctuation and removes the punctuation from them.

translate.filters.prefilters.removekdecomments(str1)

Remove KDE-style PO comments.

KDE comments start with _:[space] and end with a literal \n. Example:

"_: comment\n"
translate.filters.prefilters.varname(variable: str, startmarker: str, endmarker: str) str

Variable filter that returns the variable name without the marking punctuation.

Note

Currently this function simply returns variable unchanged, no matter what *marker’s are set to.

Returns:

Variable name with the supplied startmarker and endmarker removed.

translate.filters.prefilters.varnone(variable: str, startmarker: str, endmarker: str) str

Variable filter that returns an empty string.

Returns:

Empty string

spelling

An API to provide spell checking for use in checks or elsewhere.