Jessai
Jessai

Reputation: 947

How to use language properties with Spring MVC 4 and jQuery I18N?

I'm developing a web app with Spring MVC 4 and jQuery I18N. I have already checked the following links without success:

How to dynamically change language using jquery-i18n-properties and JavaScript?

How to load i18n Property file using jQuery.i18n.properties.js + Spring 3 mvc

But when I access to the page, I'm getting 404 Not found error in the developer's chrome console:

enter image description here

My project structure is:

enter image description here

In cheque.js (Brown square in structure) I have the following code:

function loadBundles(lang) {
    jQuery.i18n.properties({
        name:'messages', 
        path:'i18n/',
        mode:'both',
        language:lang,
        callback: function(){
            console.log(jQuery.i18n.prop('check_receiver'))
        }
    });
}
...
loadBundles('es');
...
  1. In the red square is the file required to use jquery.i18n.
  2. In the blue square I have the I18N properties files.
  3. In the pink square are the files that contains the web page

In the webmvc-config.xml I have the following code:

<mvc:resources location="/, classpath:/META-INF/web-resources/"
        mapping="/resources/**" />

<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" p:defaultEncoding="ISO-8859-1"
        id="messageSource" p:basenames="WEB-INF/i18n/messages"
        p:fallbackToSystemLocale="false" />

    <!-- Store preferred language configuration in a cookie -->
    <bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
        id="localeResolver">
        <property name="defaultLocale" value="es" />
    </bean>

Does the path in the javascript function is incorrect?

Is there any other file required by jQuery I18N?

Thanks in advance!!!

Upvotes: 2

Views: 2589

Answers (1)

Jessai
Jessai

Reputation: 947

Just If someone is facing the same issue, after one week this is the answer:

  1. Moved the properties files to the src/main/resources folder

  2. Changed the webmvc-config.xml ReloadableResourceBundleMessageSource code like this:

< bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" p:defaultEncoding="ISO-8859-1" id="messageSource" p:basenames="messages" p:fallbackToSystemLocale="false" />

  1. And finally the javascript function is like this:

    jQuery.i18n.properties({

    name:'messages', 
    path:'../resources/',
    mode:'both',
    language:lang,
    callback: function(){
        console.log(jQuery.i18n.prop('check_receiver'))
    }
    

    });

That was all folks!

Upvotes: 1

Related Questions