Copied to clipboard

Flag this post as spam?

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


  • Asbjørn 82 posts 195 karma points c-trib
    Feb 08, 2019 @ 07:29
    Asbjørn
    1

    Switching language using language variants

    So, I've been playing a bit with Umbraco 8 and language variants, just doing a simple test site to see how it works.

    Doing a language switcher should be something like this:

    @foreach (var (culture, infos) in Model.Cultures)
    {
        <a href="@Model.GetUrl(culture)">@culture @infos.Name</a>
    }
    

    This renders like this:

    Or in HTML:

    <a href="/">en-us Home</a>
    <a href="/">da Hjem</a>
    

    Notice that the URL is identical. Which I guess is not supposed to happen. I would expect /en-us and /da.

    In the backoffice, the English version looks normal, but the Danish version says it is not published - even though it says it is published when clicking publish.

    I tried toggling Umbraco.Core.HideTopLevelNodeFromPath to false, like you would do in Umbraco 7 for a multilingual site with multiple root nodes.

    This produces a different result:

    <a href="/home/">en-us Home</a>
    <a href="/hjem/">da Hjem</a>
    

    Now, the English URL /home works just fine - but the Danish one does not, it just gets a generic 404.

    Interestingly, the Danish version now has a different error in the backoffice: "This document is published but its url cannot be routed"

    So am I doing something wrong - or are there bugs in Umbraco 8 that prevent this from working correctly?

  • Kevin Jump 2311 posts 14696 karma points MVP 7x c-trib
    Feb 08, 2019 @ 09:28
    Kevin Jump
    2

    Hi

    Do you have Hostnames for each language setup?

    On Umbraco 7 When you are running the languages from one site you need to specify a URL in the culture and hostnames settings on the home page (right click, Culture and Hostnames)

    this is the same in Umbraco 8 ?

    enter image description here

    once you've done this you should see the URL in the info section change per language

    enter image description here

    enter image description here

    hopefully, the code will start to pick this up once it's set up ?

  • Asbjørn 82 posts 195 karma points c-trib
    Feb 08, 2019 @ 09:36
    Asbjørn
    2

    Thanks, that works. Though I'd say that is not exactly obvious, given the descriptive text doesn't even mention that you can use root-relative URLs like that.

    I usually don't set up domains on Umbraco 7. I just disable hiding top-level nodes and then use the umbracoUrlName property to make sure the URLs are /en, /da etc.

    I don't want to specify the whole domain (and port on localhost), since this makes moving between environments much more difficult. But if you can do root-relative domains like this, then that solves it nicely.

  • Kevin Jump 2311 posts 14696 karma points MVP 7x c-trib
    Feb 08, 2019 @ 09:43
    Kevin Jump
    0

    Yeah,

    I noticed on the screenshots, it says to avoid the relative URLs but i am not sure why (might just be to avoid clashes with pages?)

Please Sign in or register to post replies

Write your reply to:

Draft