为什么在某些语言环境中未正确填写 Spring MessageSource 参数? [英] Why Spring MessageSource arguments are not filled correctly in some locales?

查看:14
本文介绍了为什么在某些语言环境中未正确填写 Spring MessageSource 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mailconfirm.mail.body=<html><body><h3 style="margin: 0 0 1em;">Hi, {0}!</h3>
    To confirm your email address click on the confirmation link given bellow. If clicking on the link doesn't work, copy and paste the link in a new browser tab. <br /><br />
    <a href="http://www.domain.com/confirm_email.html?action=activate&hash={1}">http://www.domain.com/confirm_email.html?action=activate&hash={1}</a><br /><br />
    Kind regards,<br />
    Your Something
    </body></html>

以上是用于下面代码的特定消息.

This above is the particular message used for the code bellow.

String country = "AU";
Object[] args = new Object[] { account.getLogin(), confirm.getHash() };

helper.setText(appContext.getMessage("mailconfirm.mail.body", args,
                new Locale(country)), true);

我调试了两个参数,它们都有正确的值.调试 appContext.getMessage 行时,我看到 {1} 参数未填充正确的值,但 {0} 是.

I debugged both arguments and they both have the right values. When debuging appContext.getMessage line, I saw that the {1} param is not filled with correct value however {0} is.

有什么想法可能是错的吗?我怀疑这可能是一些语言环境问题.

Any ideas what could be wrong? I suspect it could be some locale issue.

推荐答案

问题解决了!问题似乎是因为邮件 mailconfirm.mail.body 在 {0} 之后和 {1} 之间的某处包含一个撇号.将 doesn't 替换为 does not 后,它解决了问题.我不知道那里不能使用撇号.附言这是一个错误还是只是我的错误,应该转义撇号?

Issue solved! It appears that the problem was because the message mailconfirm.mail.body contained an apostrophe somewhere after {0} and between {1}. After replaced doesn't with does not it fixed the problem. I didn't know apostrophes can't be used in there. P.S. Is it a bug or just my mistake and apostrophes should be escaped?

mailconfirm.mail.body=<html><body><h3 style="margin: 0 0 1em;">Hi, {0}!</h3>
    To confirm your email address, click on the confirmation link given bellow. If clicking on the link doesn't work, copy and paste the link in a new browser tab. <br /><br />
    <a href="http://www.domain.com/confirm_email.html?action=activate&hash={1}">http://www.domain.com/confirm_email.html?action=activate&hash={1}</a><br /><br />
    Kind regards,<br />
    Your Something
    </body></html>

一个花了我大约一个小时来弄清楚并推动修复.哈哈哈..从现在开始我认为撇号是邪恶的!

One doesn't took me about an hour to figure it out and push a fix. Hahaha.. From now on I consider apostrophes being evil!

这篇关于为什么在某些语言环境中未正确填写 Spring MessageSource 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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