I've just started to build a site that needs to support multiple languages. I've seen several posts/articles on doing this before but it's only now that I've actually been required to build one myself.
From what I understand, one of the best approaches is to create a tree for each language (which I've done) so that I have the following:
Content - en -- home -- about -- gallery - ru -- home -- about -- gallery
I've got a re-direct on each of the 'language' nodes to redirect to the home page in that particular tree. I've also set the hostnames for both of the language nodes ie. en: www.myurl.com/en and ru: www.myurl.com/ru.
On top of this I've also set the 'umbracoHideTopLevelNodeFromPath' to false, as this seemed to sort out a problem I was having with the navigation in each tree.
This all seems to be working so far. Each of the urls seem to point to the correct trees. However what I'd like is to be able to detect the browser culture settings and also redirect to the correct tree based on that.
I had a look at another thread where the OP was having a similar problem and tried putting the following code into my master page:
//Insert your startup logic here
if (Request.UserLanguages != null && (Request.ServerVariables["script_name"] == "/" || Request.ServerVariables["script_name"] == "/default.aspx"))
{
string language = Request.UserLanguages[0];
if (!string.IsNullOrEmpty(language))
{
//Get the culture name - and make sure it's in the RFC 1766 standard <languagecode2>-<country/regioncode2>
//i.e. en-GB, so it's easier to check for
if (language.Length < 3)
language += "-" + language.ToUpper();
//Redirect to the correct page based on language, default to english
switch (language.ToLower())
{
case "en-us":
Response.Redirect("/en");
break;
case "ru-ru":
Response.Redirect("/ru");
break;
default:
Response.Redirect("/en");
break;
}
}
}
This however didn't work. Since my 'en' item is the first item in the tree, the site obviously loads this node first but it seems to bypass the above code. I thought it'd hit the "/" or "/default.aspx" page first and THEN redirect to the first node in the tree but that's not how it seems to work.
I've also thought about creating a custom global.asax to implement the above logic but now I'm starting to wonder if I'm really on the right track here? Can anyone advise on what I should do in this situation?
Setting up a multi-language site
Hi guys,
I've just started to build a site that needs to support multiple languages. I've seen several posts/articles on doing this before but it's only now that I've actually been required to build one myself.
From what I understand, one of the best approaches is to create a tree for each language (which I've done) so that I have the following:
Content
- en
-- home
-- about
-- gallery
- ru
-- home
-- about
-- gallery
I've got a re-direct on each of the 'language' nodes to redirect to the home page in that particular tree. I've also set the hostnames for both of the language nodes ie. en: www.myurl.com/en and ru: www.myurl.com/ru.
On top of this I've also set the 'umbracoHideTopLevelNodeFromPath' to false, as this seemed to sort out a problem I was having with the navigation in each tree.
This all seems to be working so far. Each of the urls seem to point to the correct trees. However what I'd like is to be able to detect the browser culture settings and also redirect to the correct tree based on that.
I had a look at another thread where the OP was having a similar problem and tried putting the following code into my master page:
This however didn't work. Since my 'en' item is the first item in the tree, the site obviously loads this node first but it seems to bypass the above code. I thought it'd hit the "/" or "/default.aspx" page first and THEN redirect to the first node in the tree but that's not how it seems to work.
I've also thought about creating a custom global.asax to implement the above logic but now I'm starting to wonder if I'm really on the right track here? Can anyone advise on what I should do in this situation?
Thanks!
is working on a reply...