更改`mylocale`时jQuery验证动态更改语言错误消息

时间:2016-06-26 10:00:41

标签: javascript jquery

在我的主页上,我可以更改语言:href="home?mylocale=ru"<script src="resources/assets/js/messages_ru.min.js"></script>。我使用jQuery验证电子邮件和密码输入。当我添加href="home?mylocale=ru"时,所有消息都被翻译为俄语,但我只想在选择'variables Dim name As String = Application.ProductName Dim location As String = Application.ExecutablePath 'registry key Dim regestry As Microsoft.Win32.RegistryKey 'adds key to registry regestry = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) regestry.SetValue(name, """" & location & """") regestry.Close() 时翻译默认语言错误消息。怎么做?

1 个答案:

答案 0 :(得分:0)

结合其他两个SO答案可以做你想做的事情:

  1. 解析并分析window.location以查看mylocale是否设置为ru(来自this回答)
  2. 动态加载脚本(来自this一个)
  3. 结果将是(在<script>标签中):

    function getParameter(paramName) {
    
        var searchString = window.location.search.substring(1),
            i, val, params = searchString.split("&");
    
        for (i=0; i<params.length; i++) {
            val = params[i].split("=");
            if (val[0] == paramName) {
                return val[1];
            }
        }
        return null;
    }
    
    
    if (getParameter("mylocale") == "ru") 
        $.getScript("resources/assets/js/messages_ru.min.js");
    

    稍加修改的版本可用于加载任何语言:

    var loc = getParameter("mylocale");
    if (loc != null) 
        $.getScript("resources/assets/js/messages_"+loc+".min.js");