gpt4 book ai didi

java - Bean 验证 : How to localize messages programmatically?

转载 作者:行者123 更新时间:2023-11-29 03:23:50 25 4
gpt4 key购买 nike

在我当前的休息服务场景中,我需要能够向各个客户端提供本地化的错误消息。

想想像 void validate(Locale locale) 这样的方法,它在接收到一些请求时在参数对象上调用。

locale 信息可以从 http headers 中挤出。

当违规消息被插入时,我如何指示/配置 validator 使用某种语言?

据我所知, validator 通过调用 Locale.getDefault() 选择使用的 Locale。

到目前为止,我找不到除this 以外的任何内容。文章不完全符合我的需要(故事太长无法讲述)。

提前致谢!

最佳答案

根据spec你有两种可能性:

使用interpolate(String, Context, Locale)或者实现 custom message interpolator .

A custom message interpolator may be provided (e.g., to interpolate contextual data, or to adjust the default Locale used).

另见:

关于java - Bean 验证 : How to localize messages programmatically?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22119545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com