issues integrating language switcher with other components

Topics: Developer Forum, Project Management Forum
Jun 13, 2007 at 4:34 PM
Edited Jun 13, 2007 at 4:36 PM
Hi christian,
I don't know it this will be of any use to you, but I wrote for myself a new language switcher attribute.
This will be useful for users that want to integrate the cms with other components. Sometimes components allows you to specify some links. Since those links often can't be internationalized easily a possibility is to store the information about the language in a somewhat persistent structure like a session or user's cookies.This is what my code does. You can look for it as I've posted an issue with the same name as this post attaching the source code.


Jun 14, 2007 at 10:06 PM
Thats great. I'll make sure to include it in the next release. I'm sure it will be useful.

Jun 15, 2007 at 12:29 PM
The code I've sent you has one little problem in it, I have now a working version with a workaround, as soon as I come up with something more elegant, this should be in the next few days, I ll send the new version to u.
Jun 15, 2007 at 2:08 PM
Ok, cool. While you're at it. I only looked very quickly at the code but would you consider separating the the http module functionality into a separate class. I got the feeling the attribute is doing a bit too many things (you know, separation of concerns).

Jun 18, 2007 at 3:00 PM
I've fixed the problem in the code, it seems that whit whenever you check if a cookie is in the Response.Cookies collection, if it doesn't exist an empty cookie is automatically added to that collection... (see Mysterious Case of the Disappearing Cookie).
Also I moved the HttpModule out of the language switcher to another class.
Anyway Feel free to modify it or tell me to modify it
...I think you're a better component designer than me...!
Probably you would also want to move the 2 classes to a new namespace.
I've sent the new files as a reply to the issue previously posted

Jun 20, 2007 at 12:07 AM
Hi again. I started along the lines of making the httpmodule responsible of knowing the current language but didn't get it quite right. Especially concerning that double browser window you described in the comments. Anyway, it's getting late and for what it's worth, I checked it in. The code looks something like this:

    void  IHttpModule.Init(HttpApplication context)
		context.BeginRequest += new EventHandler(DetermineLanguage);
	/// <summary>
	/// Tries to determine current language from querystring or cookie setting,
	/// default to first language.
	/// </summary>
	static void DetermineLanguage(object sender, EventArgs e)
		HttpApplication application = sender as HttpApplication;
		if (application.Request[QueryStringParamter] != null)
			CurrentLanguage = application.Request[QueryStringParamter];
		else if (application.Request.Cookies[CookieParameter] != null)
			CurrentLanguage = application.Request.Cookies[CookieParameter].Value;
			CurrentLanguage = LanguageSwitcherAttribute.getLanguageList()[0];
	public static string CurrentLanguage
		get { return (string)HttpContext.Current.Items[CurrentLanguageKey]; }
		set { HttpContext.Current.Items[CurrentLanguageKey] = value; }
Jun 20, 2007 at 4:31 PM
Hi Christian,
I think that I've understood better what you meant after your last post.
Today I've been workin' on it, separating the concerns of knowing current language etc, from the actual serving of the right content.
I've come up with a new version that I've just sent to u as an attachment to the issue.
The name of the new file is LanguageSwitcher(20-06-2007)(NEW).rar
Hope it can be of some interest to you.