您的位置:首页 > 产品设计 > UI/UE

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.

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
>
Fortheendusertheswitchbetweenthelanguageswilllooklikethis:





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>
Thiscontrolisnorocketscience.WhatitactuallydoesistorenderallsupportedlanguagesandswitchtheLCIDusingJavaScript.Thisalsoincludeseverythingthatyouneedtoknowtobuildyourowncustomcontroltoembeddirectlyintothemasterpage.

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>
Nowworkdoneandifyouclickthedesiredlanguageitwillchangetheuserinterfacetotheselectedlanguage.InmycaseIchangedthetitleofthewebsitetoproveifthelanguagegettingswitched.




WebsiteinEnglish




WebsiteinGerman

EmbeddingwithCustomWebPartorUserControl

Nowthatthebasicsaresetit’sreallyeasytowriteawebpartforembeddingthelanguageswitchonawebpartpageorausercontroltoembeddingthisinthemasterpage.Thesamplebeforeisreallystaticsoitdoesn’tdetectthesupportedlanguagedynamically.TodetectallyouneedtouseistheSupportedUIwhichisaSPWebmethod.AttheendthehandlinginofthelanguageoftheUIisreallyeasyandIthinkthemostusecaseforthisifyouhaveapublishingwebsiteoramulti-languageIntranetSite.SharePointisprettyopentodocustomdevelopmentandsomethingsaredirectlydocumentedinthe“code”,butremember:Neverchangedefaultcodebutyoucanuseit.

原文地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐