2012-04-01 25 views
0

我正在使用spring和hibernate框架创建一个通用类。我的应用程序支持两种语言“英语”和“法语”。 每当用户填写表单并提交表单时,使用ajax进行请求。如果发生任何错误,那么一个json被发送到客户端。我的问题是,如何在JavaScript中使用 标记。我的AJAX功能是:在javascript中使用国际化

function doAjaxPost() { 
    // get the form values 
    var userName = $('#userName').val(); 
    var password = $('#password').val(); 

    $.ajax({ 
     type: "POST", 
     url: "index.htm", 
     data: "userName=" + userName + "&password=" + password, 
     success: function(response){ 
      // we have the response 
      if(response.status == null){ 
       errorInfo = ""; 
       for(i =0 ; i < response.result.length ; i++){ 
        errorInfo += response.result[i].code + "</br>"; 
       } 
       $("#loginErrors").html(errorInfo); 
       showErrors(); 
      } 
     }, 
     error: function(e){ 
      alert('Error: ' + e); 
     } 
    }); 
} 

在errorInfo中唯一的错误代码写入,但我怎样才能从我的属性文件翻译这个错误代码。

请帮我...

回答

0

如果你已经装载到MessageSource你的属性文件,您可以使用spring:message tag将您的所有代码的翻译。

请注意,您需要配置LocaleResolver或LocaleChangeInterceptor才能使其工作。