Add multilingual audit CI pipeline + extract mandelblog_content_guard
This commit is contained in:
31
mandelblog_content_guard/normalizers/es.py
Normal file
31
mandelblog_content_guard/normalizers/es.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
|
||||
ES_LINE_REPLACEMENTS = {
|
||||
"Transparente sobre la planificación, el proceso y la gestión.": "Transparencia sobre la planificación, el proceso y la gestión.",
|
||||
"<p>Transparente sobre la planificación, el proceso y la gestión.</p>": "<p>Transparencia sobre la planificación, el proceso y la gestión.</p>",
|
||||
"Preguntas frecuentes Transparente sobre la planificación, el proceso y la gestión.": "Preguntas frecuentes Transparencia sobre la planificación, el proceso y la gestión.",
|
||||
"Preguntas frecuentes Transparenteee sobre la planificación, el proceso y la gestión.": "Preguntas frecuentes Transparencia sobre la planificación, el proceso y la gestión.",
|
||||
"Planificar la reunión inicial Mostrar los proyectos Unverbindliches Gespräch, klares Angebot Construimos sitios web y tiendas online rápidas que tu equipo puede gestionar sin complicaciones.": "Planificar la reunión inicial · Mostrar los proyectos · Conversación sin compromiso con propuesta clara. Construimos sitios web y tiendas online rápidas que tu equipo puede gestionar sin complicaciones.",
|
||||
}
|
||||
|
||||
ES_PHRASE_REPLACEMENTS = {
|
||||
"Transparenteee": "Transparente",
|
||||
"Transparent": "Transparente",
|
||||
"Unverbindliches Gespräch, klares Angebot": "Conversación sin compromiso con propuesta clara",
|
||||
}
|
||||
|
||||
|
||||
def normalize_es_text(text: str, field_path: str = "") -> str:
|
||||
if text in ES_LINE_REPLACEMENTS:
|
||||
return ES_LINE_REPLACEMENTS[text]
|
||||
cleaned = text
|
||||
for source, target in sorted(ES_PHRASE_REPLACEMENTS.items(), key=lambda item: len(item[0]), reverse=True):
|
||||
if re.fullmatch(r"[\wÀ-ÿ-]+", source, flags=re.UNICODE):
|
||||
pattern = re.compile(rf"(?<![\wÀ-ÿ-]){re.escape(source)}(?![\wÀ-ÿ-])", re.UNICODE)
|
||||
cleaned = pattern.sub(target, cleaned)
|
||||
else:
|
||||
cleaned = cleaned.replace(source, target)
|
||||
return re.sub(r"\s+", " ", cleaned).strip()
|
||||
Reference in New Issue
Block a user