# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.
# a character set containing the keys in ACCENTED_STRINGS # We should not accent characters in an escape sequence such as "\n". # To be safe, we assume every character following a backslash is an escaped # character. We also need to consider the case like "\\n", which means # a blackslash and a character "n", we will accent the character "n".
TO_ACCENT = lazy_re.compile(
r'[%s]|\\[a-z\\]' % ''.join(ACCENTED_STRINGS.keys()))
# Lex text so that we don't interfere with html tokens and entities. # This lexing scheme will handle all well formed tags and entities, html or # xhtml. It will not handle comments, CDATA sections, or the unescaping tags: # script, style, xmp or listing. If any of those appear in messages, # something is wrong.
TOKENS = [ lazy_re.compile( '^%s' % pattern, # match at the beginning of input
re.I | re.S # html tokens are case-insensitive
) for pattern in
( # a run of non html special characters
r'[^<&]+', # a tag
(r'?[a-z]\w*'# beginning of tag
r'(?:\s+\w+(?:\s*=\s*'# attribute start
r'(?:[^\s"\'>]+|"[^\"]*"|\'[^\']*\'))?' # attribute value
r')*\s*/?>'), # an entity
r'&(?:[a-z]\w+|#\d+|#x[\da-f]+);', # an html special character not part of a special sequence
r'.'
) ]
ALPHABETIC_RUN = lazy_re.compile(r'([^\W0-9_]+)')
RLO = u'\u202e'
PDF = u'\u202c'
def PseudoRTLString(text): '''Returns a fake bidirectional version of the source string. This code is
based on accentString above, in turn copied from Frank Tang. '''
parts = [] while text:
m = None for token in TOKENS:
m = token.search(text) if m:
part = m.group(0)
text = text[len(part):] if part[0] notin ('<', '&'): # not a tag or entity, so accent
part = ALPHABETIC_RUN.sub(lambda run: RLO + run.group() + PDF, part)
parts.append(part) break return''.join(parts)
def PseudoRTLMessage(message): '''Returns a pseudo-RTL (aka Fake-Bidi) translation of the provided message.
Args:
message: tclib.Message()
Return:
tclib.Translation() '''
transl = tclib.Translation() for part in message.GetContent(): if isinstance(part, tclib.Placeholder):
transl.AppendPlaceholder(part) else:
transl.AppendText(PseudoRTLString(part))
return transl
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.