Sitecore 4 have the simplest way of choosing language. Just add a link with the parameter ?lg=language (where language is the language to switch to, DA for example).
Many of my websites is multilanguage sites. At the top of each page I have thses “Change language” links listed:
<a href="?lg=da">Danish</a> <a href="?lg=en">English</a>
But what happens if the page itself is called with parameters? The messageboard for example gets the post id as parameter. In this case my language links will make the page fail.
I developed this small function that returns all current parameters formatted as a new querystring so the parameters can be appended to my links:
using System.Web; using System.Text; public static string Parameters(bool firstParameterAvailable) { string Exclude = "[path][layout][lang]"; StringBuilder sb = new StringBuilder(); NameValueCollection qs = HttpContext.Current.Request.QueryString; foreach (string s in qs.AllKeys) { if (Exclude.IndexOf( "["+s+"]" ) == -1) { if (sb.Length == 0 && !firstParameterAvailable) sb.AppendFormat("?{0}={1}", s, qs[s]); else sb.AppendFormat("={1}", s, qs[s]); } } return sb.ToString(); }
I then include the function in an XslExtension class and can then use it from my XSLT code:
<a href="{Parameters(1)}">UK</a>
Well this article helped me. Thank you :)
LikeLike