l.t.u.s.Sanitizer(object) : class documentation

Part of lp.translations.utilities.sanitize View In Hierarchy

Provide a function to sanitize a translation text.
Method __init__ Extract information from the English singular.
Method sanitize Return 'translation_text' or None after doing some sanitization.
Method convertDotToSpace Return 'translation_text' with the 'dot' char exchanged with a
Method normalizeWhitespace Return 'translation_text' with the same trailing and leading
Method normalizeNewlines Return 'translation_text' with newlines sync with english_singular.
Class Method _getNewlineStyle Find out which newline style is used in text.
def __init__(self, english_singular):
Extract information from the English singular.
@classmethod
def _getNewlineStyle(cls, text):
Find out which newline style is used in text.
def sanitize(self, translation_text):
Return 'translation_text' or None after doing some sanitization.

The text is sanitized through the following filters:

self.convertDotToSpace self.normalizeWhitespaces self.normalizeNewlines

If the resulting string after these operations is an empty string, it returns None.

Parametersenglish_singularThe text of the singular MsgId that this translation is for.
translation_textA unicode text that needs to be sanitized.
def convertDotToSpace(self, translation_text):
Return 'translation_text' with the 'dot' char exchanged with a normal space.

If the english_singular contains that character, 'translation_text' is returned without changes as it's a valid char instead of our way to represent a normal space to the user.

def normalizeWhitespace(self, translation_text):
Return 'translation_text' with the same trailing and leading whitespace that self.singular_text has.

If 'translation_text' has only whitespace but english_singular has other characters, the empty string (u'') is returned to note it as an untranslated string.

def normalizeNewlines(self, translation_text):
Return 'translation_text' with newlines sync with english_singular.

Raises an exception if the text has mixed newline styles.

API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.