SharePoint Multi-languages with JavaScript Code
A my friend asked me how to implement Multi-languages with JavaScript in SharePoint 2010.
With server code, you can use resourced for this.
With JavaScript, you can identify the current language that SharePoint Site is using via _spPageContextInfo object (Ref: http://trungpv.blogspot.com/2011/09/javascript-notes-with-sharepoint.html), it provides the currentLanguage property that allows you know which language is using.
You can define an JavaScript objects like below:
News.DefaultLanguage = 1033;
News.Resources = {};
//English
News.Resources[1033] = {
Title: "News",
Function: "Searcj"
};
//Vietnamese
News.Resources[1066] = {
Title: "Tin tức",
Function: "Tìm kiếm"
};
And you can load appropriated resources:
if (News.Resources[_spPageContextInfo.currentLanguage]) {
res = News.Resources[_spPageContextInfo.currentLanguage];
} else {
res = News.Resources[News.DefaultLanguage];
}
Comments
Post a Comment