Copied to clipboard

Flag this post as spam?

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


  • Lukaz 44 posts 203 karma points
    Feb 26, 2019 @ 14:26
    Lukaz
    0

    Umbraco v8 Multilanguage

    Hi, how to make a language menu to switch between the languages ( two or more) in Umbraco v8?

  • Markus Johansson 1936 posts 5864 karma points MVP 2x c-trib
    Feb 26, 2019 @ 14:47
    Markus Johansson
    3

    Hi!

    • Under "Settings -> Languages", add the languages you want to use.

    • Then set "Culture and Hostnames" for the root node, one url for each culture.

    • You also need to set "Allow varying by culture" to true on your document types.

    You might need to reload the page to see the language switcher over the content tree (at least I had to do that).

    Cheers!

    // m

  • Lukaz 44 posts 203 karma points
    Feb 26, 2019 @ 14:49
    Lukaz
    1

    I did that. there is all ok. I need razor code to show language link names all avaiable languages on master layout.

  • Markus Johansson 1936 posts 5864 karma points MVP 2x c-trib
    Feb 26, 2019 @ 14:53
    Markus Johansson
    103

    Stephan Gray from the HQ has made some really good presentations on V8 basics over the last months,

    https://www.zpqrtbnk.net/documents

    In one of them I found this little snippet

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

    Edit: Where intlHomePage would be the Models Builder class name of your current document type.

  • Lukaz 44 posts 203 karma points
    Feb 27, 2019 @ 09:40
    Lukaz
    0

    @Markus, thank you for your effort it helped a lot.

    My setup for test porpuses:

    => Languages: English (en-us) default, Danish (da) and Genman (de)

    => Managed "Culture and Hostnames" for the root node, one url for each culture as you mentioned above.

    => Document Type: Home with setting "Allow varying by culture" set to true on document type, and textstring input named "Language" also set Allow varying by culture to true.

    => Templates

    Master Layout:

       @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = null;
    }
    
    <html>
        <head>
            <title>Multilanguage setup test</title>
        </head>
    
        <body>
            <div> Choose language:<br>
                @foreach (var (culture, infos) in Model.Cultures)
                {
                    <a href="@Model.GetUrl(culture)">
                        @Model.Value("language", culture)
                   </a>
                }
            </div>
    
            @RenderBody()
        </body>
    </html>
    

    Home template:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Home>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "master.cshtml";
    }
    
    <p>
        @Model.Value("language")
    </p>
    

    And in Content section for each homepage I added short language name.

    As you mentioned in previous post that intlHomePage wolud be Models Builder name, in my case Home if I'm not mistaken -> after runing site I'm getting error that Home is not available in current context so I rename it to Model and it works.

  • Markus Johansson 1936 posts 5864 karma points MVP 2x c-trib
    Feb 27, 2019 @ 12:11
    Markus Johansson
    1

    Hi!

    Great that you found your way around! =D

    I came to think about a presentation that I made during the Swedish Umbraco Festival some months ago, you can download the slides here:

    http://www.enkelmedia.se/blogg/2018/11/16/umbraco-sweden-festival-2018.aspx

    There is an example in there as well.

    Cheers!

  • Tony Lorentzen 85 posts 174 karma points
    Apr 24, 2019 @ 09:00
    Tony Lorentzen
    0

    What would I have to do if I wanted a combination of the language chooser on page level as well as on main language level? Let's say I'm on a page that doesn't have a German (or whatever) variant of that specific page, then I'd like to navigate to the German front page instead of directly to the German variant of the current page. How would I go about doing that?

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Apr 24, 2019 @ 09:25
    Paul Wright (suedeapple)
    0

    I think in the backoffice you can set a fallback language/culture.

    enter image description here

  • Tony Lorentzen 85 posts 174 karma points
    Apr 24, 2019 @ 09:49
    Tony Lorentzen
    0

    Thanks for the feedback Paul - however it's not working. I'm also not getting the correct links to the correct language version using the code above even if fallback language is selected or not.

  • Bo Jacobsen 606 posts 2404 karma points
    Jun 27, 2019 @ 07:04
    Bo Jacobsen
    0

    Hi all.

    How do you get this to work on localhost?

  • Lukaz 44 posts 203 karma points
    Jul 22, 2019 @ 06:56
    Lukaz
    3

    For anyone who has error issues with Umbraco 8.1.0 creating language switcher and particular code @Model.GetUrl(culture), here is the answer:

    https://our.umbraco.com/forum/umbraco-8/98097-language-switcher-error-on-810

  • Mubeen 15 posts 126 karma points
    Oct 03, 2019 @ 07:31
    Mubeen
    0

    Hello Everyone!

    I tried this code @foreach (var (culture, infos) in Model.Cultures) {

  • @Model.Value("language", culture)
  • }

    But @Model.Value("language", culture) is not working for me. It returns an empty string in every iteration. Any suggestions?

    Thanks!

Copy Link
  • MaartenVissers 32 posts 150 karma points
    Mar 06, 2020 @ 12:03
    MaartenVissers
    6

    My menu looks like this:

    <ul>
      <li>
        <a href="@Model.Url("fr")">FR</a>
      </li>
      <li>
        <a href="@Model.Url("en")">EN</a>
      </li>
    </ul>
    

    This will automatically redirect to the current page in the language you clicked on.

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

    Your solution will look something like this.

    Copy Link
  • Dagim Belayneh 1 post 21 karma points
    Mar 20, 2023 @ 16:22
    Dagim Belayneh
    0

    Here is what I did to make a language switcher that works on every page.

                     @foreach (var (culture, infos) in home.Cultures)
                        {
                            <li class="active">
                                <a href="@home.Url(culture)@Model.UrlSegment">
                                    @home.Value("language", culture)
                                </a>
                            </li>
                         }
    

    @home is a variable for the content at root

    var home = Umbraco.ContentAtRoot().ToList()[0];
    

    I have created a property called Language at the Document type of my home page and this will include the language texts I want to show (NL, FR,DE in my case)

    Copy Link
  • Please Sign in or register to post replies

    Write your reply to:

    Draft