0

I am using a Spring MVC (Spring-Security) project, When the user changes the language from the given dropdown menu, the given text in a particular language should get displayed. I tried in the following way but I am getting ??????????? in the browser when Hindi or Marathi text is selected.

JSP PAGE

This is the dropdown when the user can change the language

<div class="dropdown">
    <select id="languageId">
        <option value="English">English</option>
        <option value="Hindi">Hindi</option>
        <option value="Marathi">Marathi</option>
    </select>           
</div>

This are the text box which gets displayed when selected the particular language :

<label id="english">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500.
</label>

<label id="hindi" class="KrutiDev_hindi_text">
खरिदने एकत्रित अपनि लक्षण गटको लक्ष्य मार्गदर्शन पहोच। सहायता और्४५० मुक्त काम संसाध गयेगया प्रौध्योगिकी आपको जैसे बाटते सभिसमज प्रव्रुति कीसे पहोचने वार्तालाप विचरविमर्श विवरण तरीके लचकनहि 
</label>

<label id="marathi">
इनपुट साधने वेबवर कुठेही, आपण निवडलेल्‍या भाषेमध्‍ये टाइप करणे सोपे बनवतात.
</label>

Javascript code for on change of dropdown option :

 $(function () {
    $("#languageId").change(function () {
    if($(this).val() == 'Hindi') {
        var hindi = document.getElementById('hindi');
        hindi.style.removeProperty("display");
        $('#english').css('display','none');
        $('#marathi').css('display','none');
    }
    if($(this).val() == 'English') {
        var english = document.getElementById('english');
        english.style.removeProperty("display");
        $('#hindi').css('display','none');
        $('#marathi').css('display','none');
    }
    if($(this).val() == 'Marathi') {
        var marathi = document.getElementById('marathi');
        marathi.style.removeProperty("display");
        $('#hindi').css('display','none');
        $('#english').css('display','none');
    }
});
}); 

CSS

@font-face {
font-family: 'Kruti Dev';
src: url('fonts/Kruti-Dev.ttf') format('truetype')}

.KrutiDev_hindi_text {
font-family: Kruti Dev !important;
font-size: 12px !important;}

I have also added <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> and updated Text file encoding to UTF_8 from Properties -> Resources.

Can anyone please help me what I am missing so that I can get the other languages text.

Mayur Kandalkar
  • 204
  • 1
  • 5
  • 14

1 Answers1

0

If anyone wants to display other languages or UTF-8 characters,

it worked for me when I added this in configuration file :

Added MessageSource :

MessageSource helps application developers handle various complex scenarios with writing much extra code, such as environment-specific configuration, internationalization, or configurable values.

<bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
         <property name="defaultEncoding" value="UTF-8" />
</bean>
    
<bean id="validator"
    class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
        <property name="validationMessageSource" ref="messageSource"/>
</bean>
     
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="en" />
</bean>
    
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />
</bean> 

I have added messages.properties

hindi=\u092E\u0948\u0902 \u0935\u0947\u0930\u093E\u0938\u093F\u0938 

marathi=\u092E\u0948\u0902 \u0935\u0947\u0930\u093E\u0938\u093F\u0938 

I have also updated my jsp :

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<spring:message code="hindi"/>

<spring:message code="marathi"/>
Mayur Kandalkar
  • 204
  • 1
  • 5
  • 14