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

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

问题描述

mailconfirm.mail.body=<html><body><h3 style="margin: 0 0 1em;">{0}!</h3>\要确认您的电子邮件地址,请单击下面给出的确认链接.如果单击链接不起作用,请将链接复制并粘贴到新的浏览器选项卡中.<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/>\亲切的问候,<br/>\你的东西</body></html>

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

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} 是.>

任何想法可能是错误的?我怀疑这可能是一些语言环境问题.

解决方案

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

mailconfirm.mail.body=<html><body><h3 style="margin: 0 0 1em;">{0}!</h3>\要确认您的电子邮件地址,请单击下面给出的确认链接.如果单击链接不起作用,请将链接复制并粘贴到新的浏览器选项卡中.<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/>\亲切的问候,<br/>\你的东西</body></html>

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

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);

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.

解决方案

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天全站免登陆