如何加载i18n属性文件?

时间:2016-07-04 14:12:52

标签: jquery spring

我的Web应用程序中需要JavaScript i18n,它基于Spring MVC。

当我运行示例应用程序时,它可以正常工作,但在我将其集成到我的应用程序中时则不行。

我的JavaScript代码无法加载属性文件。

这是我的项目结构。

Here is my project structure.

login.jsp中的jquery:

jQuery(document).ready(function() {
        loadBundles('de');

        // configure language combo box
        jQuery('#lang').change(function() {
            var selection = jQuery('#lang option:selected').val();
            loadBundles(selection !== 'browser' ? selection : null);
            jQuery('#langBrowser').empty();
            if(selection === 'browser') {
                jQuery('#langBrowser').text('('+jQuery.i18n.browserLang()+')');
            }
        });

    });
        function loadBundles(lang) {
                            jQuery.i18n.properties({
                                name:'messages', 
                                path:'src/main/resources', 
                                mode:'both',
                                language:lang, 
                                callback: function() { 
                $("#msg_welcome").text($.i18n.prop('user.success')); $("#msg_selLang").text($.i18n.prop('user.lang', lang)); 
                }
        });
    };

的login.jsp:

                          <body>
    <div id="mainWrapper">
        <div class="login-container">
            <div class="login-card">
                <div class="login-form">
                    <c:url var="loginUrl" value="/login" />
                                            <form:form action="${loginUrl}" method="POST" class="form-horizontal" modelAttribute="users">
                        <c:if test="${param.error != null}">
                            <div class="alert alert-danger">
                                <p>Invalid username and password.</p>
                            </div>
                        </c:if>
                        <c:if test="${param.logout != null}">
                            <div class="alert alert-success">
                                <p>You have been logged out successfully.</p>
                            </div>
                        </c:if>
                        <div class="input-group input-sm">
                            <label class="input-group-addon" for="username"><i class="fa fa-user"></i></label>
                            <input type="text" class="form-control" id="login" name="login" placeholder="Enter Username" required>

                        </div>
                        <div class="input-group input-sm">
                            <label class="input-group-addon" for="password"><i class="fa fa-lock"></i></label> 
                            <input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required>
                        </div>

                                                    <div class="input-group input-sm">
                                                        Language:
                                                    <select id="lang">
                                                    <option value="browser">Indicated by the browser</option>
                                                            <option value="en">en</option>
                                                            <option value="de" selected>de</option>
                                                            <option value="ru">ru</option>
                                                      </select>
                                                      <span id="langBrowser"></span>

                                                      </div>

                                                    <div class="input-group input-sm">
                                                        <div class="checkbox">
                                                        <label><input type="checkbox" id="rememberme" name="remember-me"> Remember Me</label>  
                                                    </div>
                        </div>
                        <input type="hidden" name="${_csrf.parameterName}"
                            value="${_csrf.token}" />

                        <div class="form-actions">
                            <input type="submit"
                                class="btn btn-block btn-primary btn-default" value="Login">
                        </div>
                    </form:form>
                </div>
            </div>
        </div>
    </div>

</body>

Chrome开发者控制台: Chrome developer console

0 个答案:

没有答案