Copied to clipboard

Flag this post as spam?

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


  • Tony Lorentzen 85 posts 174 karma points
    Mar 29, 2019 @ 13:37
    Tony Lorentzen
    0

    Code support for language variants

    So, I'm developing a multi-language website on Umbraco 8 and I'm really in need of information on how to implement language support in Umbraco 8. For example I'm using this piece of code to get my main menu:

    Model.Root().Children.Where(x => x.IsVisible()).ToArray(); 
    

    Problem is when I'm navigating from my Danish website to the German one (which doesn't have any pages published under the home-page) I'm still getting those pages from the Danish version - except only the node and not with the danish nodal information in it. What the...

    Do I need to use another method for this support?

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 04, 2019 @ 19:19
    Corné Strijkert
    1

    I think you have to change your line of code to something like this:

    var currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
    
    Model.Root().Children.Where(x => x.IsVisible() && x.Cultures.ContainsKey(currentCulture)).ToArray(); 
    

    The current page Model contains values for the intended language automatically, according to the current culture, set by the culture and hostnames settings.

    When you get the children of the current page model, you will get exactly what you are asking, the children of the current page, even when that child doesn't have property values for the current culture.

  • Tom 34 posts 154 karma points
    Mar 27, 2020 @ 08:38
    Tom
    0
  • Tony Lorentzen 85 posts 174 karma points
    Mar 27, 2020 @ 09:58
    Tony Lorentzen
    0

    Great - thanks Tom. Unfortunately, that article didn't exist when I originally posted the question but thanks for the find ;-) I did manage to solve the problem back then.

  • Tom 34 posts 154 karma points
    Mar 27, 2020 @ 11:38
    Tom
    0

    No problem. Good to hear you've already solved the problem!

Please Sign in or register to post replies

Write your reply to:

Draft