You can use a virtual directory in the iis and point it to an common folder for all langauge depend pages.
e.g
/en/yourPage.aspx
/es/yourPage.aspx
the directory structur could be :
\bin
\common\yourPage.aspx
\controls\.....
to switch the language read the current page, create some links to the current page and prepend the
different langauge codes to the links.
- for a first-time visitor, read whose language from the request
- to redirect a visitor to the last visited language, use a coockie
- if a user type an unavailable languagecode in the url, implement a mehtod to
define a default system language.
- then set the language to the current thread
protected void Application_BeginRequest(Object sender, EventArgs e)
{
String language = Request.UserLanguages[0];
if (language.Length > 1) language = language.Substring(0, 2);
HttpCookie cookie = Request.Cookies["ReBuy"];
if (cookie != null && cookie["language"] != null)
{
language = (String)cookie["language"];
}
if (splitPath.Length > 1)
{
if (splitPath[0].Length == 2)
{
language = splitPath[0];
}
else if (splitPath[1].Length == 2)
{
language = splitPath[1];
}
}
language = Bll.Language.Language.GetSystemLanguage(language);
if (cookie == null)
{
cookie = new HttpCookie("myappname");
}
if (cookie["language"] == null || cookie["language"].ToString() != language)
{
cookie["language"] = language;
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
}
joschua
Member
40 Points
8 Posts
Re: How to do a language switch in a master page.
May 05, 2006 08:58 AM|LINK
e.g
/en/yourPage.aspx
/es/yourPage.aspx
the directory structur could be :
\bin
\common\yourPage.aspx
\controls\.....
to switch the language read the current page, create some links to the current page and prepend the
different langauge codes to the links.
- for a first-time visitor, read whose language from the request
- to redirect a visitor to the last visited language, use a coockie
- if a user type an unavailable languagecode in the url, implement a mehtod to
define a default system language.
- then set the language to the current thread
protected void Application_BeginRequest(Object sender, EventArgs e)
{
String language = Request.UserLanguages[0];
if (language.Length > 1) language = language.Substring(0, 2);
HttpCookie cookie = Request.Cookies["ReBuy"];
if (cookie != null && cookie["language"] != null)
{
language = (String)cookie["language"];
}
String appName = Request.ApplicationPath.Length > 1 ? Request.ApplicationPath : "";
String path = this.Request.FilePath.Substring(appName.Length);
String[] splitPath = path.Split('/');
if (splitPath.Length > 1)
{
if (splitPath[0].Length == 2)
{
language = splitPath[0];
}
else if (splitPath[1].Length == 2)
{
language = splitPath[1];
}
}
language = Bll.Language.Language.GetSystemLanguage(language);
if (cookie == null)
{
cookie = new HttpCookie("myappname");
}
if (cookie["language"] == null || cookie["language"].ToString() != language)
{
cookie["language"] = language;
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
}
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(language);
}
I hope it helps you.