Recommendation on the usage of language and/or locale in Sit

Posted by Community Admin on 03-Aug-2018 19:19

Recommendation on the usage of language and/or locale in Sitefinity

All Replies

Posted by Community Admin on 18-Mar-2013 00:00

I am looking for a recommendation on the usage of language and/or locale in Sitefinity.

In Sitefinity you can translate content into separate languages and basically ignore the locale, or you can pair language and locale.  The problem is that the locale is specific to a country/language pair.  Instead of being country specific it would be nice to be regional specific.

For example, if a customer comes to our web site and they are from somewhere in France I want them to be transferred to the European section of our web site.  If the user comes from the United States I want them to be transferred to our North American section of our web site.

Does anyone have a recommendation on this type of setup or do you have a better idea???


Thanks,
Craig

Posted by Community Admin on 21-Mar-2013 00:00

Hello Craig,

We don't have this out-of-the-box, but you can check the browser language of the user and depending on that to redirect him to the correct location of the site. Here's an example (this is one possible approach)

Code in the global.asax file:

protected void Session_Start(object sender, EventArgs e)
  
        
  
            System.Web.HttpContext context = System.Web.HttpContext.Current;
  
            string curUrl = context.Request.Url.ToString();
  
            string browserLanguage = "";
  
            try
  
                browserLanguage = HttpContext.Current.Request.UserLanguages[0];
  
            
  
            catch
  
                browserLanguage = "en";
  
            
  
                
  
            if (browserLanguage == "de-DE")
  
            
  
                if ((curUrl == "http://www.alurehab.com") || (curUrl == "http://www.alurehab.de"))
  
                
  
                    context.Response.Redirect("http://www.alurehab.de");
  
                
  
            
  
            else if (browserLanguage == "da-DK")
  
            
  
                if ((curUrl == "http://www.alurehab.de") || (curUrl == "http://www.alurehab.com"))
  
                
  
                    context.Response.Redirect("http://www.alurehab.dk");
  
                
  
            
  
            else
  
            
  
                context.Response.Redirect("http://www.alurehab.com");
  
            
  
        
Also you can check the following code, which can be inserted in your master page ( or in the Global.asax ):
<script language="C#" runat="server">
  
        protected void Page_Load(object sender, EventArgs e)
  
                if(Request.UserLanguages != null && Request.ServerVariables["script_name"] == "/")
  
                        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)
  
                                        case "en-US":
  
                                                Response.Redirect("/home.aspx");
  
                                                break;
  
                                        case "nl-BE":
  
                                                Response.Redirect("/startpagina.aspx");
  
                                                break;
  
                                        case "fr-BE":
  
                                                Response.Redirect("/acceuil.aspx");
  
                                                break;
  
                                        default:
  
                                                Response.Redirect("/home.aspx");
  
                                                break;
  
                                
  
                        
  
                
  
        
  
</script>

Here are also some useful articles:

stackoverflow.com/.../how-to-get-visitor-location-country-state-and-city-using-asp-net

stackoverflow.com/.../how-to-get-a-current-user-location-in-asp-net

forums.asp.net/.../1416074.aspx

All the best,
Jen Peleva
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 22-Mar-2013 00:00

Thanks for the information.

This thread is closed