'Translate text.strip(), but keep the surrounding spaces from text.'

def process_text(self, text):

    term = text.strip()
    trans = (term and self.callback(term))
    if trans:
        try:
            etree.fromstring(('<div>%s</div>' % encode(trans)), parser=self.parser)
        except etree.ParseError:
            trans = escape(trans)
        text = text.replace(term, trans)
    return text
