Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Customize error messages (e.g. for translations)

Aperta
#971 8 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia dalla documentazione di ValidationError e dalla gestione di additionalProperties in jsonschema/_validators.py, incluso il suo utilizzo di _utils.find_additional_properties. Esamina l’issue correlata #564 e il contesto di errore esistente per determinare l’ambito di un meccanismo di messaggi configurabile. Il risultato dovrebbe essere un design revisionato con un modo chiaro per supportare messaggi tradotti e specifici per errore senza duplicare la logica del validatore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Enhancement Error Reporting

Hi,
I would need to translate the error messages and it happens to be more complicated than I expected (or than it could be, I believe).
I started using information on ValidationErrors to define custom messages, but all relevant information for the message is not always readily available. Found this related issue #564 but with not much follow-up so I thought I could ask again.

For instance, for an "additionalProperties" keyword, looking at the code shows that there is some logic that needs to be reimplemented to make message translations (using internal _utils.find_additional_properties to find the offending properties, two different messages depending on whether properties or patternProperties is used etc.).

In addition to the overhead this introduces, I am afraid that it may drift out of sync with the logic in this package in case of improvements, bug fixes, or new draft support etc. or that internal functions may change without backward compatibility.

I am wondering if it would be possible to not hard-code messages, but use templates instead (e.g. Jinja2), that have access to error-specific contextual data (e.g. offending properties for "additionalProperties" errors), and that could be changed for a translation without touching at the logic. This is for instance the approach taken by xeipuuv/gojsonschema.

I think it would be worth a try, and I would be willing to contribute on this with a little help, if you think it is a good idea.

Lingua principale
Python
Stelle
5k
Fork
694
Merge medio
1g 20h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-jsonschema/jsonschema

Tutte le issue di python-jsonschema/jsonschema

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.