Change language of UI using custom control in SharePoint 2010
2011-11-08 15:16
573 查看
InSharePoint2010theusersnowcanswitchtheuserinterfacebetweendifferentlanguagesifseverallanguagepacksareinstalled.HowtoenableandhowthisworkscanbefoundonBeckyBertram’sBlog.Shedidareallygoodjobondescribinghowyouareabletoenableandtranslatetheuserinterfacetodifferentlanguages.Itisalsothebestselectionofotherblogposts.That’sallaboutthebasicfrommyside.
AfteryouenabledmultipleLanguagesupportforonewebsitetheuserareabletoswitchonthesocalled“welcomecontrol”,whichcanbefoundinthefarrightcorneroftheuserinterface.
Fortheendusertheswitchbetweenthelanguageswilllooklikethis:
Soinmyopinionthisfeatureisnicelyhiddenintheuserinterface.CertainSharePointuserwillfindthistherebutwhatifIwanttoswitchthelanguagedirectlyusingtheinterface?
ThecontrolfromaboveisstoredintheHIVE14\Templates\controltemplates\andiscalledMUISelectior.ascx.Hereisthecode:
Thiscontrolisnorocketscience.WhatitactuallydoesistorenderallsupportedlanguagesandswitchtheLCIDusingJavaScript.Thisalsoincludeseverythingthatyouneedtoknowtobuildyourowncustomcontroltoembeddirectlyintothemasterpage.
WhatthiscontrolbasicallydoesistorenderthesupportedlanguagesandtheJavaScriptsetssimplythecookieontheclienttothedifferentlanguage.Inthenextstepslet’strythisoutwithasimplewebpart.
Nowworkdoneandifyouclickthedesiredlanguageitwillchangetheuserinterfacetotheselectedlanguage.InmycaseIchangedthetitleofthewebsitetoproveifthelanguagegettingswitched.
WebsiteinEnglish
WebsiteinGerman
SupportedUIwhichisaSPWebmethod.AttheendthehandlinginofthelanguageoftheUIisreallyeasyandIthinkthemostusecaseforthisifyouhaveapublishingwebsiteoramulti-languageIntranetSite.SharePointisprettyopentodocustomdevelopmentandsomethingsaredirectlydocumentedinthe“code”,butremember:Neverchangedefaultcodebutyoucanuseit.
原文地址
AfteryouenabledmultipleLanguagesupportforonewebsitetheuserareabletoswitchonthesocalled“welcomecontrol”,whichcanbefoundinthefarrightcorneroftheuserinterface.
Thedefaultcontrol
Inthemasterpageyoucanidentifythispartwiththefollowingcode:1 | < a href = "#" tabindex = "-1" style = "display:none" ></ a >< a href = "#" tabindex = "-1" style = "display:none" ></ a > |
2 | < div class = "s4-trc-container-menu" > |
3 | < div > |
4 | < wssuc:Welcome id = "IdWelcome" runat = "server" EnableViewState = "false" > |
5 | </ wssuc:Welcome > |
6 | < wssuc:MUISelector ID = "IdMuiSelector" runat = "server" /> |
7 | </ div > |
8 | </ div > |
Soinmyopinionthisfeatureisnicelyhiddenintheuserinterface.CertainSharePointuserwillfindthistherebutwhatifIwanttoswitchthelanguagedirectlyusingtheinterface?
ThecontrolfromaboveisstoredintheHIVE14\Templates\controltemplates\andiscalledMUISelectior.ascx.Hereisthecode:
1 | <%@ControlLanguage= "C#" Inherits= "Microsoft.SharePoint.WebControls.MUISelector,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" compilationMode= "Always" %> |
2 | <%@RegisterTagprefix= "SharePoint" Namespace= "Microsoft.SharePoint.WebControls" Assembly= "Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %><%@RegisterTagprefix= "Utilities" Namespace= "Microsoft.SharePoint.Utilities" Assembly= "Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %><%@ImportNamespace= "Microsoft.SharePoint" %><%@AssemblyName= "Microsoft.Web.CommandUI,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> |
3 | <scripttype= "text/javascript" > |
4 | //<![CDATA[ |
5 | functionOnSelectionChange(value) |
6 | { |
7 | vartoday= new Date(); |
8 | varoneYear= new Date(today.getTime()+365*24*60*60*1000); |
9 | varurl=window.location.href; |
10 | document.cookie= "lcid=" +value+ ";path=/;expires=" +oneYear.toGMTString(); |
11 | window.location.href=url; |
12 | } |
13 | //]]> |
14 | </script> |
15 | <selectid= "DdLanguages" onchange= "javascript:OnSelectionChange(this.value);" runat= "server" > |
16 | </select> |
WhatthiscontrolbasicallydoesistorenderthesupportedlanguagesandtheJavaScriptsetssimplythecookieontheclienttothedifferentlanguage.Inthenextstepslet’strythisoutwithasimplewebpart.
EmbeddingwithHTMLFormWebPart
ThiswillusetheHTMLFormWebPartbecausethisistheonlywebpartasfarasIknowallowswritingJavaScriptinside.WhatIwilldoisbasicallyaddtwolinksforGermanandEnglishandalittlecustomizedJavaScript.ThecodeisalsoquitesimpleandtakenandmodifiedfromthedefaultMUIControl.1 | <scripttype= "text/javascript" > |
2 | //<![CDATA[ |
3 | functionChangeMUI(value) |
4 | { |
5 | vartoday= new Date(); |
6 | varoneYear= new Date(today.getTime()+365*24*60*60*1000); |
7 | varurl=window.location.href; |
8 | document.cookie= "lcid=" +value+ ";path=/;expires=" +oneYear.toGMTString(); |
9 | window.location.href=url; |
10 | } |
11 | //]]> |
12 | </script> |
13 | <ahref= "javascript:ChangeMUI(1031)" >German</a> | <ahref= "javascript:ChangeMUI(1033)" >English</a> |
WebsiteinEnglish
WebsiteinGerman
EmbeddingwithCustomWebPartorUserControl
Nowthatthebasicsaresetit’sreallyeasytowriteawebpartforembeddingthelanguageswitchonawebpartpageorausercontroltoembeddingthisinthemasterpage.Thesamplebeforeisreallystaticsoitdoesn’tdetectthesupportedlanguagedynamically.Todetectallyouneedtouseisthe相关文章推荐
- Deploy custom Css,Js files in SharePoint 2010 using visual studio 2010
- Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010[Sharepoint中添加自定义菜单]
- sharepoint ECMA using a custom contentType to creating a list in SubSite
- 【转载】Adding Validation to a Custom List Control in Sharepoint
- Multiple Attachment custom control in Sharepoint
- Using taxonomyfields in SharePoint 2010 By bhoeijmakers
- SharePoint Development - Custom Field using Visual Studio 2010 based SharePoint 2010
- Custom Ribbon in SharePoint 2010 & which not wrok when migrate from 2010 to 2013
- Change UIVersion Of SharePoint 2010
- Show username instead of "System Account" in SharePoint 2010
- 【Vegas原创】Change Title of Existing Site Collection in Sharepoint
- 【Vegas原创】Change Title of Existing Site Collection in Sharepoint
- SharePoint 2010: Create a Custom Page Layout for a Publishing Site using SharePoint Designer
- How to hide my site and my document link in the right-top corner of sharepoint 2010
- 【Vegas原创】Change Title of Existing Site Collection in Sharepoint
- SharePoint Development - Custom Content Type using Visual Studio 2010 based SharePoint 2010
- SharePoint Development - Custom List using Visual Studio 2010 based SharePoint 2010
- [Override]Using Developer Dashboard in SharePoint 2010
- Force stop and then start a full crawl on all content sources in a SharePoint 2010 farm using PowerShell(转)
- delegate control in sharepoint 2010