Apostrophe doesn't get translated properly when placed in a resource bundle
将Apostrophe放在资源包中后,翻译不正确。
1 2 3 | key = {0}'s brush is {1} centimeters tall (e.g. Sam's brush is 4 centimeters tall) |
如果我从
您应该将单引号转义为
1 | key = {0}''s brush is {1} centimeters tall |
我坚信问题不是资源束,而是用于打印消息的MessageFormater:
从MessageFormater Java文档:
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}'''.
所以你需要写:
1 | {0}''s brush is {1} centimeters tall |
在这里看javadoc
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}'''".
如果您像我一样完全卡住了(上述方法均无效),则可以将单引号替换为其Unicode:\ u0027。请记住,始终允许您在属性文件中使用UTF符号。
添加到@Ralph的答案:
当您有类似这样的文本时,您将意识到这是
1 | text1=It's too late |
与
1 | text2={0}''s too late |
因此,如果您在
您需要将单引号加倍,即{0}的画笔高{1}厘米
考虑使用Properties Editor插件(对于Eclipse)
http://propedit.sourceforge.jp/index_en.html
对于在string.xml中遇到Android问题的每个人,请使用\'\'而不是单引号。