Nibble

Adding a language selector to your multilingual umbraco site

Create mutlilingual sites with umbraco, there are several approaches in doing this, the one I use the most is to have multiple ‘top level’ nodes (I’ll make a screencast of this in a future post). So for each language you would have a top level node.

The content tree would look like this:

languageselectorcontent

I would like to add a language selector on the site, a dropdown with all languages that will redirect to the selected langauge homepage. How to do this ?

languageselector

I’ll first add a new property to the top level node document type. This will store the text that is displayed in the dropdown.

languageselectordocumenttype

Next step is to create a new xslt file (with macro).

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ &lt;!ENTITY nbsp “&#x00A0;”> ]>
<xsl:stylesheet 
    version=”1.0″ 
    xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” 
    xmlns:msxml=”urn:schemas-microsoft-com:xslt”
    xmlns:umbraco.library=”urn:umbraco.library”
    exclude-result-prefixes=”msxml umbraco.library”>
 
 
<xsl:output method=”xml” omit-xml-declaration=”yes”/>
 
<xsl:param name=”currentPage”/>
 
 
            
 
<xsl:template match=”/”>
<form>
<select name=”langselection” onchange=”loadPage(this.form.elements[0])” target=”_parent._top” >
<option selected=”selected”>– Please select –</option>
 
  <xsl:for-each select=”$currentPage/ancestor::root/node”>
         
         <option value=”{umbraco.library:NiceUrl(@id)}”><xsl:value-of select=”data [@alias = ‘language’]”/></option>      
    
  </xsl:for-each>
</select>
</form>
 
</xsl:template>
 
</xsl:stylesheet>

This will output the html code for the dropdown. The most important part is the for-each loop, wich will loop all top level nodes, add the url of the top level node as a value of the dropdown option and add the content of the language property as the displayed text of the drop down option.

Now you can add the macro to your template, but you’ll also need to add a little javascript.

<script language=“JavaScript”>
 
function loadPage(list) {
 
  location.href=list.options[list.selectedIndex].value
 
}
 
</script>

32 Comments so far

  1. Ryan on April 15th, 2009

    Any chance you could extend this post to cover how to set up multilanguage sites using Umbraco (either 1:1 or multiple directories).

    There are NO good resources out there that cover this. The umbraco documentation is really poor. Looking at the Umbraco forum this is a common issue/problem in the umbraco community.

  2. vijay on December 30th, 2009

    Hi,

    Can u give me clear idea on how to implement Multi language site.
    if possible please send me any sample code how to display content in different languages…..

    vijay

  3. Great on February 22nd, 2010

    It work fine, thanks.

  4. Haroon on December 15th, 2010

    Umbraco documentation is really very poor. I m a .net developer but new to umbraco and I cant find any good help on how to set up multilingual applications with umbraco… If anyone knows any good site, plz refer me as I m not getting the starting point…

  5. umit kavala on January 6th, 2011

    hi, I have tried but dropdown shown empty. I have added new generic property and set these properties on root nodes for eng and arabic. but it didn’t work.
    could you please help me? I am doing something wrong?

  6. anthony on January 7th, 2011

    I had the same problem as Umit: empty dropdownlist. Could it be this line that is written for an older schema:

    greetings,

    Anthony

  7. anthony on January 7th, 2011

    I have tried it out, it’s indeed the schema:

    One has to change the above code to this:

    – Please select –

  8. Jhansi Nadella on May 23rd, 2011

    How to create login form in Umbraco pls help me

  9. Jhansi Nadella on May 23rd, 2011

    Can u give me clear idea on how to implement Multi language site.
    if possible please send me any sample code how to display content in different languages…..

  10. Jhansi Nadella on May 23rd, 2011

    Can u give me clear idea on how to implement Multi language site in Umbraco CMS.
    if possible please send me any sample code how to display content in different languages…..

  11. Alexey Shevchenko on September 5th, 2011

    I have same problem with some other users. Dropdown list is empty.

  12. Mike on January 16th, 2012

    Hi,

    I’ve almost the correction, replace the “for-each” by :

    but I’ve one element, one the current page only…

  13. Mike on January 16th, 2012

    Code here :

    — $currentPage/ancestor-or-self::* [@isDoc and @level=1] — in the select of for-each

  14. norton.com/setup on January 27th, 2017

    We have an umbraco installation with mixed languages in the backend. When I switch the language for my user to “English (United Kingdom)” or “English (USA)” I still see some german words in the backend, e.g. “Durchsuchen” instead of “Type to search…” in the search box or “Entwickler” instead of “Developer”, but not everywhere. As i cannot send picture or so can’t show you you screenshort.

  15. BullGuard Login on March 12th, 2020

    BullGuard Internet Security is an extraordinary cybersecurity programming that offers bleeding edge insurance for all your associated gadgets. This all encompassing work area application gives you tenacious security for Windows, Mac and Android gadgets.

  16. MyDrive Connect - TomTom Update | TomTom Home

  17. McAfee Login on September 3rd, 2020

    McAfee Login permits you the access of security of all your devices protected by its state-of-the-art security cover. In other words, it allows you to access its User Account. With McAfee Antivirus Software, you get a laser-sharp security solution that is best-of-the-breed.

  18. McAfee Activate on September 3rd, 2020

    Before the beginning of the process, purchase the McAfee Product online or either through the retail store. In case of purchasing the product from an online store, you can grab the product key from the order confirmation mail of McAfee.

  19. www.webroot.com/safe on September 3rd, 2020

    With the emerging trend of new and advanced cyberthreats, cybersecurity solutions need constant innovation and upgradations. Webroot is one such cybersecurity specialist that displays the potential to challenge the existing and emerging threats. This makes it a globally accredited security solution for safeguarding your digital life.

  20. office.com/verify on September 3rd, 2020

    MS Office works tirelessly to assure that its users get the best of productivity tools with utmost convenience. For this reason, it offers a user-friendly online platform that helps in quick and easy setup.

  21. Norton Setup on September 3rd, 2020

    Norton Setup is a vital process that ensures unparalleled cybersecurity solutions. The process is simple and quick which begins by purchasing a suitable product. Thereafter, you can download, install and activate your purchased Norton product Key.

  22. mail.aol.com on September 4th, 2020

    AOL Mail includes a variety of services i.e. AOL mail, AOL Instant Messenger, AOL Video, video search, news, sports, weather, etc. With the help of AOL Mail, you can connect to the millions of people across the world.

  23. TurboTax Login on September 4th, 2020

    First and foremost, you should open your preferred internet browser on your computer. You may have Internet Explorer, Google Chrome, Firefox, Safari, etc. Hence, you have to open any of these browsers available on your computer.

  24. TurboTax Login on September 4th, 2020

    In today’s world of ever-evolving cyber threats, securing your systems, data, identity and privacy has become a daunting task. It is because of this reason that antivirus software has become an essential component for any computing device.

  25. norton.com/setup on September 4th, 2020

    Norton is an antivirus software that protects your devices against viruses, malware, spyware, and other online attacks. It helps you in avoiding unsafe websites by giving you regular alerts.

  26. bitdefender login on September 4th, 2020

    With the help of remote setup method of Bitdefender Central, you can also attach the parental control to the devices. Using this software user can use the Bitdefender products online and can make changes to the devices in which this software is being installed.

  27. garmin login on September 4th, 2020

    Garmin is a leading champion of consumer and professional class products that integrates the cutting edge GPS technology. It offers an enormously wide range of products for aviation, automotive, marine, outdoor, fitness and sports activities.

  28. BT Mail on September 4th, 2020

    BT Mail – Login to My BT Account or do BTinternet Sign in to enjoy the Email Services and you may also create an BT Account.

  29. hp printer setup on September 4th, 2020

    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

  30. Belkin Setup on September 4th, 2020

    Belkin is an American multinational brand of innovative consumer electronic and networking devices. It is a pioneer in delivering cutting-edge technology to its global users in the form of user-friendly gadgets.

  31. Hulu Login on September 15th, 2020

    Entertainment can be more fun with Hulu as here you get access to a world full of your favorite TV shows. Here will get the opportunity to enjoy the latest content that you can stream in any of your devices supporting the app. Get your free trial and access to your device in the

  32. Garmin.com/Express on September 15th, 2020

    Garmin Express is an extremely versatile software application available for both Windows and Mac devices. However, you are required to check the specified requirements and ensure your system conforms to it. This is extremely important for flawless setup and unmatched performance.

Leave a Reply