In this tutorial, you will learn how to get a multi-language URL within an Episerver CMS powered website. On the current pages
PageData object, you can use the
LinkURL property to get the URL for the default language in Episerver CMS. This value will always be set to the current language. If you are working with a multi-language website, however, you will likely need to generate a link to a different language variation. How do you do this? Read on to learn how 🔥🔥🔥
In order to generate a link to a specific language, you can use one of a few techniques:
Manually: Out-of-the-box, the Episerver multi-language feature works by appending a language segment onto the URL. For example,
www.website.com/en/ for English, or,
www.website.com/fr/ for French. The quick and easy way to create a URL on the root domain is to add the segment yourself using string concatenation, e.g.
Via an API: The manual technique is horrible, so let us get onto something that is more flexible, the
This util method is doing the same code as above, it will just do it on every URL. You can use the
ILanguageBranchRepository API to get the enabled cultures (read this tutorial to learn more).
Instead of passing in the language code, you can also pass the helper language ID as an overload. You can re-write the code above using the
page.LanguageID property, like this:
As long as the language ID mirrors up to the language you want to access, you should be golden! Those are three ways to get the URL for a specific language. Happy Coding 🤘