撇号放在资源包中时无法正确翻译

发布于 2024-10-08 01:57:27 字数 209 浏览 6 评论 0原文

撇号放在资源包中时无法正确翻译。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

心房的律动 2024-10-15 01:57:27

您应该将单引号转义为

key = {0}''s brush is {1} centimeters tall

You should escape the single quote as

key = {0}''s brush is {1} centimeters tall
〃安静 2024-10-15 01:57:27

我坚信问题不在于资源包,而在于 用于打印消息的 MessageFormater

From MessageFormater java 文档

在字符串中, '' (两个单引号)代表一个
单引号。 QuotedString 可以
包含任意字符,除了
单引号;周边单人
引号被删除。不带引号的字符串
可以包含任意字符
除了单引号和左卷曲
括号。因此,一个字符串应该
结果是格式化的消息
'{0}' 可以写成 '''{'0}''
或 '''{0}'''。

所以你需要写:

{0}''s brush is {1} centimeters tall

I strongly belive that the problem is not the ressource bundle but the MessageFormater you use to print the message:

From MessageFormater java doc:

Within a String, '' (two single quotes ) represents a
single quote. A QuotedString can
contain arbitrary characters except
single quotes; the surrounding single
quotes are removed. An UnquotedString
can contain arbitrary characters
except single quotes and left curly
brackets. Thus, a string that should
result in the formatted message
'{0}' can be written as '''{'0}''
or '''{0}'''.

So you need to write:

{0}''s brush is {1} centimeters tall
风和你 2024-10-15 01:57:27

添加@Ralph的答案:
text1这样的文本时,你会意识到这是一个 MessageFormat 东西,

text1=It's too late

当你有像

text2={0}''s too late

它可能不会通过 MessageFormater 运行(例如,如果传递参数,spring 具有不同的代码路径或不会),而 text2 会。
因此,如果您在 text1 中使用了两个单引号,它们可能会这样显示。因此,您需要检查是否有任何参数被格式化,并相应地使用一两个单引号。

Adding to @Ralph's answer:
You will realize that this is a MessageFormat thing when you have a text like

text1=It's too late

versus

text2={0}''s too late

text1 would probably not run through a MessageFormater (e.g. spring has different code paths if arguments are passed or not), whereas text2 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.

假装爱人 2024-10-15 01:57:27

如果您像我一样完全陷入困境(以上方法都不起作用),您可以将撇号替换为其 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.

幽梦紫曦~ 2024-10-15 01:57:27

查看这里的javadoc

在字符串中,“''”代表一个
单引号。 QuotedString 可以
包含任意字符,除了
单引号;周边单人
引号被删除。不带引号的字符串
可以包含任意字符
除了单引号和左卷曲
括号。因此,一个字符串应该
结果是格式化的消息
“'{0}'”可以写成“'''{'0}''”
或“'''{0}'''”。

Look at the javadoc here

Within a String, "''" represents a
single quote. A QuotedString can
contain arbitrary characters except
single quotes; the surrounding single
quotes are removed. An UnquotedString
can contain arbitrary characters
except single quotes and left curly
brackets. Thus, a string that should
result in the formatted message
"'{0}'" can be written as "'''{'0}''"
or "'''{0}'''".

等数载,海棠开 2024-10-15 01:57:27

您需要加双单引号,即 {0}' 的画笔高度为 {1} 厘米

You need to double single quote i.e. {0}''s brush is {1} centimeters tall

九命猫 2024-10-15 01:57:27

考虑使用 Properties Editor 插件(适用于 Eclipse)

http://propedit.sourceforge.jp/index_en.html

Consider using Properties Editor plugin (for Eclipse)

http://propedit.sourceforge.jp/index_en.html

寄人书 2024-10-15 01:57:27

对于在 string.xml 中遇到 Android 问题的每个人,请使用 \'\' 而不是单引号。

For everyone that has Android problems in the string.xml, use \'\' instead of single quote.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文