How to generate a Episerver Page Url for a specific language

When you work with the LinkURL property in the PageData object in EPiServer, the Url will always be set to the current language. If you are working with a multi-language website, however, sometimes you need to create links to different languages dynamically. In order to generate a link to a specific language, you can use one of the following methods:

Manually Adding A Link

Out of the box, Episervers multi-language feature works by appending a language segment into the URL as a query string, so for example for my website, I would add a language parameter, like so:
The simple way to create a language on a page is to change the /en/ part to the language you care about.

Dynamically Creating a Link For A Page

Ok so the last section is quite a horrible way so let's get onto something that is more flexible.
var swedishLink = EPiServer.UriSupport.AddLanguageSelection(page.LinkURL, "sv");
In the back end, all this really does is appending the language query string as 'sv'. When the page loads, Episerver will read in this value in the route definition and load the correct page accordingly. Besides passing in the culture code you care about, you can also use the page.LanguageID property to get it automatically from the page, so the code above could also be generated like this:
var swedishLink = EPiServer.UriSupport.AddLanguageSelection(page.LinkURL, page.LanguageID);
As long as the page instance you are using is the Swedish version.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-35662136-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + ''; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();