撇号放在资源包中时无法正确翻译
撇号放在资源包中时无法正确翻译。
key = {0}'s brush is {1} centimeters tall
(e.g. Sam's brush is 4 centimeters tall)
如果我从 java.util.ResourceBundle
格式化上述密钥,就会错过撇号,这可能是什么问题?
Apostrophe doesn't get translated properly when placed in a resource bundle.
key = {0}'s brush is {1} centimeters tall
(e.g. Sam's brush is 4 centimeters tall)
The apostrophe gets missed if I format the above key from a java.util.ResourceBundle
What could be the problem here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您应该将单引号转义为
You should escape the single quote as
我坚信问题不在于资源包,而在于 用于打印消息的 MessageFormater:
From MessageFormater java 文档:
所以你需要写:
I strongly belive that the problem is not the ressource bundle but the MessageFormater you use to print the message:
From MessageFormater java doc:
So you need to write:
添加@Ralph的答案:
text1
这样的文本时,你会意识到这是一个MessageFormat
东西,当你有像
它可能不会通过 MessageFormater 运行(例如,如果传递参数,spring 具有不同的代码路径或不会),而
text2
会。因此,如果您在
text1
中使用了两个单引号,它们可能会这样显示。因此,您需要检查是否有任何参数被格式化,并相应地使用一两个单引号。Adding to @Ralph's answer:
You will realize that this is a
MessageFormat
thing when you have a text likeversus
text1
would probably not run through a MessageFormater (e.g. spring has different code paths if arguments are passed or not), whereastext2
would.So if you used two single quotes in
text1
, they may / will display as such. So you'll need to check if any arguments get formatted in or not and use one or two single quotes accordingly.如果您像我一样完全陷入困境(以上方法都不起作用),您可以将撇号替换为其 Unicode:\u0027。请记住,您始终可以在属性文件中使用 UTF 符号。
If you are completely stuck, as I was (none of the above worked), you can replace the apostrophe sign with its Unicode: \u0027. Remember you are always allowed to use UTF symbol in your properties file.
查看这里的javadoc
Look at the javadoc here
您需要加双单引号,即 {0}' 的画笔高度为 {1} 厘米
You need to double single quote i.e. {0}''s brush is {1} centimeters tall
考虑使用 Properties Editor 插件(适用于 Eclipse)
http://propedit.sourceforge.jp/index_en.html
Consider using Properties Editor plugin (for Eclipse)
http://propedit.sourceforge.jp/index_en.html
对于在 string.xml 中遇到 Android 问题的每个人,请使用 \'\' 而不是单引号。
For everyone that has Android problems in the string.xml, use \'\' instead of single quote.