Apostrophe is not translated properly when placed in a resource bundle

An apostrophe cannot translate correctly when placed in a resource package.

key = {0} brush is {1} centimeters tall (eg Sam brush is 4 centimeters tall) 

Apropot is skipped if I format the above key from java.util.ResourceBundle What could be the problem here?

+63
java resourcebundle
Dec 15 '10 at 11:59
source share
8 answers

You should avoid single quotes as

 key = {0}' brush is {1} centimeters tall 
+89
Dec 15 '10 at 12:02
source share

I really believe that the problem is not in the ressource package, but in the MessageFormater that you use to print the message:

From MessageFormater java doc :

Inside a string, `` '' (two single quotes) is a single quote. The QuotedString function can contain arbitrary characters except single quotes; ambient single quotes are deleted. UnquotedString can contain arbitrary characters besides single quotes and left curly brackets. Thus, the string that should result in a formatted message '{0}' can be written as '' '{' 0} '' or '' '{0}' ''.

So you need to write:

 {0}' brush is {1} centimeters tall 
+23
Dec 15 '10 at 12:02
source share

Check out javadoc here

The String "'" "represents a single quote in the string. The QuotedString function can contain arbitrary characters except single quotes; the surrounding single quotes are deleted. UnquotedString can contain arbitrary characters other than single quotes and the left curly bracket. Thus, the string that should result in a formatted one message "'{0}'" can be written as "'' '{' 0} ''" or "'' '{0}' ''".

+6
Dec 15 2018-10-15
source share

You need to double the single quote ie {0} 'brush {1} centimeters high

+5
Dec 15 '10 at 12:03
source share

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

 text1=It too late 

against

 text2={0}' too late 

text1 will probably not work through MessageFormater (for example, spring has different code codes if arguments are passed or not), while text2 will. Therefore, if you used two single quotes in text1 , they can / will be displayed as such. Therefore, you need to check if any arguments are formatted or not, and use one or two single quotes, respectively.

+3
Feb 02 '16 at 7:32
source share

If you are completely stuck, like me (none of the above), you can replace the apostrophe with your Unicode: \ u0027. Remember that you are always allowed to use the UTF character in the properties file.

+3
Jun 24 '16 at 16:00
source share

Consider using the property editor plugin (for Eclipse)

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

+2
Dec 15 '10 at 12:25
source share

For anyone who has Android issues in the string.xml file, use \ '\' instead of a single quote.

+1
Jul 30 '14 at 17:02
source share



All Articles