INNER CODE UNIT · Python
respell_text
OpenChemistry/avogadrolibs · scripts/copy-default.py:216
def respell_text(text, locale):
"""Respell a run of plain text (no markup) for the locale."""
text = WORD_RE.sub(common_word, text)
if locale in ISE_LOCALES:
text = ISE_RE.sub(swap_z, text)
text = YSE_RE.sub(swap_z, text)
return text
def respell(text, locale):
"""Respell text for the locale, leaving markup and URLs untouched."""
if locale not in RESPELL_LOCALES or not text:
return text
pieces = MARKUP_RE.split(text)
for i in range(0, len(pieces), 2):
pieces[i] = respell_text(pieces[i], locale)
return ''.join(pieces)