Best Practices
General > Best Practices > Multilingual feature : switch culture version View modes: 
User avatar
Member
Member
wahid - 4/7/2005 11:11:28 PM
   
Multilingual feature : switch culture version
To switch from a culture version to another for the same page I use a LinkButton with this code:

// I am in a "fr-ca" culture version page :
private void LinkButtonLanguage_Click(object sender, System.EventArgs e) {
Session["CMSPreferredCulture"] = "en-ca"; //change culture version session variable
//If the cookie doesn't exist, creates it
if (Request.Cookies["CMSPreferredCulture"].Value == null)
Response.Cookies.Add(new HttpCookie("CMSPreferredCulture", "en-ca"));
else
Response.Cookies["CMSPreferredCulture"].Value = "en-ca";
Response.Redirect("~" + Functions.GetAliasPath()); //Redirect to the same aliaspath
}

To switch back I just change "en-ca" with "fr-ca".
But it doesn't work in both directions.
What does really change the current culture version? Session["CMSPreferredCulture"] or the Cookie Response.Cookies["CMSPreferredCulture"].Value?

Do you guys have a better way to do it?

Thanks

User avatar
Guest
admin - 4/8/2005 2:00:38 PM
   
Re: Multilingual feature : switch culture version
Hi Wahid,

Thank you for your post. Actually, the Session variable specifies the culture code for the controls, the cookie is used only for page templates since the URL Rewriting engine doesn't have access to the session.

Your code seems to be fine. Here's another method that is new and it's not mentioned in the documentation yet (we will add it soon): you can create a link href="?lang=en-ca". It calls the same page and the Global.asax code sets the culture correctly.

It's ensured by this method:
public void Application_AcquireRequestState( object sender, EventArgs e ) 
{
// set language if required
if ( ( !( Request.QueryString[ "lang" ] == null ) ) && Request.QueryString[ "lang" ] != "" )
{
Session[ "CMSPreferredCulture" ] = Request.QueryString[ "lang" ];
}
}

Unfotunately, this code does not set the cookie variable - we will add it in the nearest release. You can add the following line now:

Response.Cookies["CMSPreferredCulture"].Value = "en-ca";

Please let me know if this helps.

Regards,

User avatar
Member
Member
wahid - 4/26/2005 6:19:10 AM
   
Re: Multilingual feature : switch culture version
Yes it helped very well.

Thank you again Petr!