覆盖播放 2.0 的默认 i18n 消息 [英] Overriding default i18n messages for play 2.0

查看:21
本文介绍了覆盖播放 2.0 的默认 i18n 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用@Constraint.Required 来验证表单的字段,这会生成一个ValidationError - 这一切都很好.此错误有一个标准错误消息 (error.required),它与以下字符串相关联:此字段是必需的".

We use @Constraint.Required to validate the fields of our forms, and this generates a ValidationError - which is all well and nice. This error has a standard error message (error.required) which is associated with the following string: "This field is required".

然而,我们想要控制这个字符串并且(可能)覆盖它——我们怎么做呢?我们的 conf/-文件夹中有一个消息文件,其中包含以下行:

However, we want to have control over this string and (possibly) override it - how can we do this? We have a message file in our conf/-folder which has the following line:

error.required = dummytext

但错误消息仍然显示此字段是必需的" - 即使正在读取消息文件(我们进行了一些测试).

But the error message still reads "this field is required" - even though the messages-file is being read (we did some tests).

我们如何覆盖这些消息?

How can we override these messages?

谢谢!

推荐答案

这不是一个很好的解决方案,尤其是当您想要制作多语言应用程序时.因此,在这种情况下,将更改的消息放在注释中会失败.

That's not quite good solution especially when you want to make multilingual app. So placing changed messages in annotations will fail in such case.

幸运的是,有解决方案,可以按预期工作.您需要将标签放入以语言代码作为扩展名的语言文件中,即.conf/messages.en,即使只定义了一种语言并且是英语.

Fortunately there is solution, which works as expected. You need to place your labels into the language file with language code as an extension ie. conf/messages.en, even if there is only one language defined and it's English.

可以从 Play 的来源

这篇关于覆盖播放 2.0 的默认 i18n 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆