Copied to clipboard

Flag this post as spam?

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


  • Naru 3 posts 23 karma points
    Mar 13, 2011 @ 23:07
    Naru
    0

    Create a multilingual site using Umbraco


    Hello,

    I've been looking into building a simple multilingual website using Umbraco. The main point is that I would not want to have different folders and pages for different languages. I am looking for the equivalent of what we can have in a basic .NET web application: unique web pages pages and several resource files (*.resx), where the pages contain keys, whose values can be determined at runtime dependening on the language the user chooses to view the application in.

    I have already followed the video tutorial:
    http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls

    So I know the resource files can be used... I just need a language selector, say a drop down list... I actually tried to make such a user control and add it side by side to my HelloWorld user control, but didn't work, as we cannot change the application's culture using a user control:
    http://stackoverflow.com/questions/3209105/asp-net-changing-a-sites-culture-programmatically
    http://stackoverflow.com/questions/4876520/programmatically-set-culture-of-user-controls-in-asp-net

    So I could put the language selector in the master page? What is the recommended approach? I've been searching about this topic, and found lots of references to the broken link:
    http://our.umbraco.org/books/multilingual-11-sites ... It would be nice to read a bit about this topic before proceeding... If any one can provide me with any advice or references, I'd appreaciate it a lot.

    Thanks in advance.

     

  • Sherry Ann Hernandez 320 posts 344 karma points
    Mar 14, 2011 @ 06:35
    Sherry Ann Hernandez
    1

    I use a global.asax to change the culture

     protected override void Application_BeginRequest(object sender, EventArgs e)
            {
                base.Application_BeginRequest(sender, e);
                HttpCookie cookie = new HttpCookie("lang");
                if (Request.QueryString["lang"] != null)
                {
                    String lang = Request.QueryString["lang"];
                    cookie.Value = Request.QueryString["lang"];
                   
                    Response.Cookies.Add(cookie);
           
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
                }
                else if (Request.Cookies["lang"] != null )
                {
                    cookie = Request.Cookies["lang"];
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
                }
                else
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                }
                
            }

     And then delete the one used by umbraco.

  • Naru 3 posts 23 karma points
    Mar 26, 2011 @ 23:34
    Naru
    0

     

    Thank you Sherry for your suggestion and for sharing your code.

    I ended up with a somewhat different appoach, an http module, but still used the cookies! I wasn't being able to get a compiled App_global.asax.dll (just the Global.asax) to replace the original one, so I ended up looking into Http Handlers and Http Modules, and created an Http Module with the cookie code in the Application_BeginRequestion function:

    private void Application_BeginRequest(Object source, EventArgs e)
    {           
               HttpCookie cookie = new HttpCookie("lang");
                if (Request.Cookies["lang"] != null)
                {
                    cookie = Request.Cookies["lang"];
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
                }
    }

    Any advantages or disadvantages to one or other approach? So far it's working. Thanks!

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft