0

In my project, I'm using Resorce bundle to display multi language, everything is ok except it's couldn't display values in placeholder:

<label>
    <spring:message code="home.address"/>
</label>
<spring:message code="home.street" var="bdstreet"/>
<form:input id="txtstreet" class="form-control" path="address.street" placeholder="${bdstreet}" />
<form:errors path="address.street" cssClass="error" />

English display is ok, but VietNamese is incorrect. My config:

<beans:bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <beans:property name="basenames">
        <beans:list>
            <beans:value>language/home</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>
<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/**" />
        <beans:bean id="localeChangeInterceptor"
            class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <beans:property name="paramName" value="lang" />
        </beans:bean>
    </mvc:interceptor>
</mvc:interceptors>

<beans:bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <beans:property name="cookieName" value="lang" />
    <beans:property name="defaultLocale" value="vn_VN" />
</beans:bean>
<!-- End Resource Bundle -->

Vietnamese incorrect English is ok

Ducthien
  • 417
  • 1
  • 3
  • 13

2 Answers2

0

Try to add defaultEncoding property in ResourceBundleMessageSource declaration:

<beans:bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <beans:property name="basenames">
        <beans:list>
            <beans:value>language/home</beans:value>
        </beans:list>
    </beans:property>
    <beans:property name="defaultEncoding" value="UTF-8"/>
</beans:bean>

Also, check that you file stored in utf-8 encoding.

About placeholders. It seems, that you store strings in encoded state. This means that when you'll show it in html, browser will automatically decode strings. But when you'll show it in placeholders, browser will do nothing, and will show them as is. Solution, don't encode stings in your resource. Just type strings with common letters. Example:

simple.string=Qu&#7889;c Gia  // now you store in this format

simple.string=Quốc Gia  // you should store in this format
Ken Bekov
  • 13,696
  • 3
  • 36
  • 44
0

yeah, I found my problem.

I have just changed BunderResource plugin to format my properties file. And it's working now.

(I used unikey with "NCR Decimal" before, and it display incorrect in placeholder's position)

I recreated properties file with BunderResource plugin: add Plugin to edit properties files

That plugin will reformat for me. enter image description here result is: enter image description here @Ken Bekov, thank for you help :) I use it in this: Java properties UTF-8 encoding in Eclipse

Community
  • 1
  • 1
Ducthien
  • 417
  • 1
  • 3
  • 13