Customize error messages (e.g. for translations)
还没有人认领这个 Issue。
评估
调研方向
从 ValidationError 文档以及 jsonschema/_validators.py 中对 additionalProperties 的处理开始,包括其对 _utils.find_additional_properties 的使用。查看相关 issue #564 和现有的错误上下文,以确定可配置消息机制的范围。完成后应得到一份经过审阅的设计,明确说明如何在不重复验证器逻辑的情况下支持已翻译的、特定于错误的消息。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 5k
- 派生
- 694
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-jsonschema/jsonschema 的其他 Issue
-
Iterator error contexts lose parent links and absolute paths可能已有人在做 @DawnofGenX 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
python-jsonschema/jsonschema#1584 · 3 条评论 ·
-
regex format checker crashes with RecursionError on deeply nested patterns可能已有人在做 @DawnofGenX 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
python-jsonschema/jsonschema#1538 · 1 条评论 ·
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponent可能重新可做 关联的 PR 已关闭且未合并。 未关闭Needs Test Upstream
难度 2/5 1-3 小时 新手友好度 78/100
python-jsonschema/jsonschema#1511 · 1 条评论 ·
-
regex format checker crashes with ValueError on conflicting inline flags可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
python-jsonschema/jsonschema#1558 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
python-jsonschema/jsonschema#1547 ·
查看 python-jsonschema/jsonschema 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 83/100
PedestrianDynamics/pyFDS-Evac#766 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 91/100
alchaincyf/nuwa-skill#86 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 2 天内回复
-
Docs Needs Triage
难度 1/5 1 小时以内 新手友好度 88/100
pandas-dev/pandas#71055 ·
维护者通常 1 天内回复
-
[Bug]: graphify reads files that git's global ignore file hides可能已有人在做 @smngvlkz 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
Graphify-Labs/graphify#4335 · 1 条评论 ·
维护者通常 1 天内回复