Commit 6abf3196 authored by Pierre Dittgen's avatar Pierre Dittgen

Add translate_error_code utility function in helpers

parent bfffd18b
Pipeline #2381 passed with stage
in 1 minute and 43 seconds
......@@ -27,3 +27,59 @@ def prepare_source(source_type, name, source) -> Tuple[Any, Dict]:
"scheme": scheme,
"format": format,
}
ERROR_CODE_TO_FR_LABEL = {
# Core checks
'blank-header': 'en-tête manquant',
'blank-row': 'ligne vide',
'duplicate-header': 'en-tête répété',
'duplicate-row': 'ligne dupliquée',
'extra-header': 'colonne surnuméraire',
'missing-header': 'colonne manquante',
'enumerable-constraint': 'valeur incorrecte',
'maximum-constraint': 'valeur maximale non respectée',
'maximum-length-constraint': 'longueur maximale non respectée',
'minimum-constraint': 'valeur minimale non respectée',
'minimum-length-constraint': 'longueur minimale non respectée',
# These 3 errors are skipped
# - non-matching-header
# - extra-header
# - missing-header
# and replaced by 3 aggregated errors:
# - missing-headers
# - extra-headers
# - wrong-headers-order
# missing-value
'pattern-constraint': 'erreur de format',
'required-constraint': 'valeur requise',
'type-or-format-error': 'format incorrect',
'unique-constraint': 'doublons',
# Validata pre-checks
'unknown-csv-dialect': 'structure CSV non reconnue',
'extra-headers': 'en-tête surnuméraire',
'invalid-column-delimiter': 'délimiteur de colonne incorrect',
'missing-headers': 'en-tête manquant',
'wrong-headers-order': 'en-têtes non ordonnés',
# Validata custom checks
'french-siret-value': 'n° siret invalide',
'french-siren-value': 'n° siren invalide',
'compare-columns-value': 'comparaison de colonnes invalide',
'sum-columns-value': 'somme de colonnes invalide',
'cohesive-columns-value': 'cohérence entre colonnes',
'year-interval-value': 'année ou période',
}
def translate_error_code(error_code: str):
"""Translate error code to french label.
>>> translate_error_code('french-siret-value')
'n° siret invalide'
>>> translate_error_code('foo-bar-baz')
'[foo-bar-baz]'
"""
return ERROR_CODE_TO_FR_LABEL.get(error_code, f"[{error_code}]")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment