java - How to set encoding for bundle? -
i use properties i18n. if specify non-english locale:
resourcebundle messages = resourcebundle.getbundle("i18n/messages", new locale("tr", "tr")); i see message wrong encoding:
ÐÑивеÑ! how set correct encoding?
problem: default iso 8859-1 character encoding used reading content of properties file, if file contains character beyond iso 8859-1 not processed properly.
first solution: process properties file have content iso 8859-1 character encoding using native2ascii - native-to-ascii converter
what native2ascii does: converts non-iso 8859-1 character in equivalent \uxxxx. tool because need not search \uxxxx equivalent of special character.
usage utf-8: native2ascii -encoding utf8 e:\a.txt e:\b.txt
if use eclipse notice implicitly converts special character \uxxxx equivalent. try copying
会意字 / 會意字
into properties file opened in eclipse.
second solution: create custom resourcebundle.control class can used resourcebundle read properties in given encoding scheme. may want use created , shared customresourcebundlecontrol. use below:
resourcebundle messages = resourcebundle.getbundle("i18n/messages", new customresourcebundlecontrol("utf-8"));
Comments
Post a Comment