SharePoint2010 自定义多语言切换与多语言实现 JS方式

1、自定义一个改变SharePoint 显示语言下拉框,使用JS实现功能

2、内容多语言化,使用JQ的多语言插件实现

因为多语言的切换是全局功能,还是这里为导航内容多语言化,所以JS写在母版页中了。

//在SharePoint中的JS路径。
<
script type="text/javascript" src="/_Layouts/JavaScript/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="/_Layouts/JavaScript/jquery.localisation.js"></script> <script type="text/javascript"> $(document).ready(function() { if (_spPageContextInfo.currentLanguage == "1033") { $("#divselect").val("en"); } else if (_spPageContextInfo.currentLanguage == "1028") { $("#divselect").val("zh-TW"); } var url = document.location.toString(); $("#divselect").change(function () { if(url.indexOf("lang=")>0) { url = url.substring(0,url.indexOf("lang=")-1); } if ($("#divselect").val()== "en") { if(url.indexOf('?')>0) { url = url +"&lang=1033"; }else { url = url +"?lang=1033"; } OnSelectionChange("1033",url); } if ($("#divselect").val()== "zh-TW") { if(url.indexOf('?')>0) { url = url +"&lang=1028"; }else { url = url +"?lang=1028"; } OnSelectionChange("1028",url); } }); MultLang(); }); //通过清除cookice,改变当前显示语言 function OnSelectionChange(value,url) { var today = new Date(); var oneYear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); document.cookie = "lcid=" + value + ";path=/;expires=" + oneYear.toGMTString(); window.location.href = url; } //JS通过变量名获取变量值 function getParameterByName(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.href); if(results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } //根据不同的语言动态加载JS文件,JS文件包含变量的定义;如:ideastatus-zh-TW.js ideastatus.js function MultLang() { try { var langfile; if(_spPageContextInfo.currentLanguage== "1028" ){ langfile='ideastatus-zh-TW'; } else if(_spPageContextInfo.currentLanguage== "1033") { langfile='ideastatus'; } //动态加载JS文件,注意路径问题 $.localise(langfile, {loadBase: true, path: '../_layouts/JavaScript/lang/'}); changeLangs(); } catch(e){ } } function changeLangs(){ if(_spPageContextInfo.currentLanguage!= "1033"){ //使用JQ的选择器找到要多语言化的文件,替换 $("#ideaText").html(IdeaText); } } </script> <select id="divselect" > <option value="en" >English</option> <option value="zh-TW">繁體中文</option> </select>
<div id ="
ideaText">
idea
</div>

你可能感兴趣的:(SharePoint)