【问题标题】:How to use language properties with Spring MVC 4 and jQuery I18N?如何在 Spring MVC 4 和 jQuery I18N 中使用语言属性?
【发布时间】:2015-03-24 12:13:31
【问题描述】:

我正在使用 Spring MVC 4 和 jQuery I18N 开发一个 Web 应用程序。我已经检查了以下链接但没有成功:

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

但是当我访问该页面时,我在开发者的 chrome 控制台中收到 404 Not found 错误

我的项目结构是:

cheque.js(结构中的棕色方块)我有以下代码:

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. 红色方块中是使用 jquery.i18n 所需的文件。
  2. 在蓝色方块中,我有 I18N 属性文件。
  3. 粉色方块中是包含网页的文件

webmvc-config.xml 我有以下代码:

<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>

是不是javascript函数中的路径不对?

jQuery I18N 还需要其他文件吗?

提前致谢!!!

【问题讨论】:

    标签: javascript jquery spring-mvc internationalization http-status-code-404


    【解决方案1】:

    如果有人面临同样的问题,一周后就是答案:

    1. 将属性文件移至 src/main/resources 文件夹

    2. webmvc-config.xml ReloadableResourceBundleMessageSource 代码更改如下:

    1. 最后的javascript函数是这样的:

      jQuery.i18n.properties({

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

      });

    这就是所有人!

    【讨论】:

      猜你喜欢
      • 2018-11-12
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      • 1970-01-01
      • 2016-09-05
      • 2013-08-11
      • 2013-09-18
      相关资源
      最近更新 更多