Search code examples
hrefmultilingualumbraco7

Problems with multi-language site using Umbraco


I have set up a multi language site with Umbraco 7 based on this article:https://our.umbraco.org/Documentation/Using-Umbraco/Multilanguage-Setup/

I have managed to get the general layout and first level working but am having problems with the internal links.

For example:

                <ul>
                <li><a href="/">@umbraco.library.GetDictionaryItem("Home")</a></li>
                <li><a href="/contact-us">Contact Us</a></li>
                <li><a href="/articles">@umbraco.library.GetDictionaryItem("Articles")</a></li>
            </ul>

I would expect the href to send to the content based on the current language.

My content is split as described in the article. I have multiple logical sites: myip/en, myip/he etc/

I would have expected that a click on the articles link would take me to myip/en/articles if I was on the English site. Instead it looks for myip/articles.

I have tried with and without the "/" and with and without a "~" before the slash. What am I doing wrong?


Solution

  • Umbraco does not replace links in your code, so what you expected will not work. Another thing is that "article" is properly not the same word in the "he" language. Its also bad for SEO in the url.

    You need to find the "article" node and then use .Url to get the url for this node. One way do to it would be:

    @CurrentPage.DescendantsOrSelf("Article").First().Url
    

    (assuming your template is called Article and your are on the root node)

    If you really want ":lang/article" in your url no matter what language you are on, you could create a new Dictionary item called "SiteLang", and then write "en" in en and "he" in he language.

    You could then create a link like this:

    <li><a href="@umbraco.library.GetDictionaryItem("SiteLang")/articles">@umbraco.library.GetDictionaryItem("Articles")</a></li>