Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • fabio 87 posts 107 karma points
    Jul 08, 2010 @ 13:01
    fabio
    0

    Multi Language site 1:1 Approach, accessing user language info from the web request

    Hello and thanks in advice.

    I'm new to umbraco and first of all i wanna say my little thanks for this great product.

    I'm building a multilanguage web-site with the 1:1 approach, multiple domains are not an option.

    I've read the tutorial at http://umbraco.org/documentation/books/multilingual-11-sitesit explains the most of the work i have to do.

    But i have another requirements that i summarize with:

    when the user access http://www.mygreatsite.com , read from the request object  the language code  so when it lands on the login page you could show it in the right language from the beginning.

    May be better explained here  http://www.west-wind.com/weblog/posts/334.aspx

    Could someone tell me the "right" way and place to do that?

      Thanks again 

      Fabio

     

     

     

     

     

     

     

     

     

     

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 08, 2010 @ 13:50
    Matt Brailsford
    0

    Hi Fabio.

    You could create a user control macro, that you drop at the top of your master page (if you have a master page, that all your other master pages extend from, this would be the best place). Then in that user control, on init, check the culture and store in a session variable or similar so you only check once per request.

    Matt

  • Rik Helsen 670 posts 873 karma points
    Jul 08, 2010 @ 14:32
    Rik Helsen
    0

    Here is a usercontrol that detects the language, you'll have to change it a little bit to make it do exactly what you want it to though:

    http://our.umbraco.org/forum/using/ui-questions/2814-MultiLanguage-same-Domain-?p=3

    <%@ Control Language="C#"  %>

    <script runat="server">
       
           
    public string DefaultLanguage { get; set; }

           
    public System.Collections.Generic.IList<string> Languages { get; set; }

           
    protected override void OnInit(EventArgs e)
           
    {
                base
    .OnInit(e);
               
    var preferredLanguage = "";
               
    if (Page.Request.Cookies["preferredLanguage"] != null)
               
    {
                    preferredLanguage
    = Page.Request.Cookies["preferredLanguage"].Value;
                   
    if (!String.IsNullOrEmpty(preferredLanguage))
                   
    {
                       
    Response.Redirect("/" + preferredLanguage);
                   
    }
               
    }
               
    var cookie = new HttpCookie("preferredLnguage");
                cookie
    .Expires = DateTime.Now.AddMonths(1);
               
    var redirectLanguage = "";
               
    if (Page.Request.UserLanguages != null)
               
    {
                    foreach
    (string language in Page.Request.UserLanguages)
                   
    {
                       
    if (language.Substring(0, 2).Equals("nl"))
                       
    {
                            redirectLanguage
    = "nl";
                           
    break;
                       
    }
                       
    if (language.Substring(0, 2).Equals("en"))
                       
    {
                            redirectLanguage
    = "en";
                           
    break;
                       
    }
                       
    else if (language.Substring(0, 2).Equals("fr"))
                       
    {
                            redirectLanguage
    = "fr";
                           
    break;
                       
    }
                   
    }
               
    }
               
    if (!string.IsNullOrEmpty(redirectLanguage))
               
    {
                    cookie
    .Value = redirectLanguage;
                   
    Response.Cookies.Add(cookie);
                   
    Response.Redirect("/" + redirectLanguage);
               
    }

               
    var defaultLanguage = System.Configuration.ConfigurationSettings.AppSettings["DefaultLanguageRedirect"];
               
    if (!String.IsNullOrEmpty(defaultLanguage))
               
    {
                   
    Response.Redirect(defaultLanguage);
               
    }
               
    Response.Redirect("/nl");
           
    }

    </script>

    ps. the alternative approach does not mean you need a subdomain for each language, and gives you SEO for each language instead of 1 url showing 3 languages, confusing google

    live example using this method: www.recytyre.be

  • fabio 87 posts 107 karma points
    Jul 08, 2010 @ 15:22
    fabio
    0

    thanks Matt and Rick for the fast answer ,

    i'm feeling a bit like a donkey !:-)),

    2 seconds after i hitted submit i found the post Rick Mentioned

    Thanks anyway.

     

     

  • fabio 87 posts 107 karma points
    Jul 15, 2010 @ 13:14
    fabio
    0

    i'm trying to mark this thread as solved, but i can't find the "solved" button,

    Could someone  tell me where can i find the button.

     

    Fabio

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 15, 2010 @ 13:16
    Matt Brailsford
    0

    There should be an icon below each persons name. Just click the one below the correct answer.

    Many thanks

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft