找到你要的答案

Q:Question marks instead of Unicode characters with resource bundle in view

Q:问号而不是Unicode字符视图中的资源包

I use Primefaces 3.5 + Lifaray 6.2. I need some internalization in my app. I use Language_en_US.properties file and others for string resources. In backbean I use ResourceBundle.getBundle and it's working propertly.

But in view I use

<p:outputLabel value="#{i18n['server-address']}"/>

And with Cyrillic i always got question marks on page

?????? ??????

It's in page code already as question marks, so it's not a browser problem.

If I use ResourceBundle.getBundle directly

<p:outputLabel value="#{adminBean.getString('main')}"/>

then I got Cyrillic.

Is there any way to use i18n without bean?

I use Primefaces 3.5 + Lifaray 6.2. I need some internalization in my app. I use Language_en_US.properties file and others for string resources. In backbean I use ResourceBundle.getBundle and it's working propertly.

但鉴于我使用

<p:outputLabel value="#{i18n['server-address']}"/>

我总是用西里尔问号页

????????????

它在页面代码中已经是问号,所以它不是浏览器问题。

如果我用resourcebundle.getbundle直接

<p:outputLabel value="#{adminBean.getString('main')}"/>

然后我得到了西里尔。

有没有办法使用I18N无豆?

answer1: 回答1:

Liferay expects the resource bundles to be encoded in UTF-8 (unlike PropertyResourceBundle in plain Java, which uses ISO-8859-1).

Check encoding of you Language_ru_RU.properties file - most likely it is not UTF-8. That would explain that ResourceBundle.getBundle works correctly, while #{i18n['server-address']} doesn't.

While it's a deviation from the standard, UTF-8 encoding is quite comfortable, as there's no need for character escaping.

See Localizing JSF Portlets in Liferay documentation.

Liferay预计的资源束在UTF-8编码(不同于普通java,使用ISO-8859-1 PropertyResourceBundle)。

检查你language_ru_ru.properties编码文件可能不是UTF-8。这就可以解释resourcebundle.getbundle正确工作,而# { i18n [ 'server-address ] }没有。

而来自标准偏差,UTF-8编码是很舒服的,因为没有必要的字符转义。

看到liferay文档本地化JSF portlet。

jsf  character-encoding  localization  liferay