+1-888-365-2779
Try Now
More in this section

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

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

3 posts, 0 answered
  1. Craig
    Craig avatar
    82 posts
    Registered:
    07 Apr 2009
    18 Mar 2013
    Link to this post
    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
  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    21 Mar 2013
    Link to this post
    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:

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

    http://stackoverflow.com/questions/10407921/how-to-get-a-current-user-location-in-asp-net

    http://forums.asp.net/t/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
  3. Craig
    Craig avatar
    82 posts
    Registered:
    07 Apr 2009
    22 Mar 2013 in reply to Jen Peleva
    Link to this post
    Thanks for the information.
3 posts, 0 answered