Copied to clipboard

Flag this post as spam?

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


  • julius 107 posts 289 karma points
    Oct 09, 2013 @ 22:06
    julius
    0

    Getting language of a "node" in Umbraco 6

    Hello,

    I have a multi-language website with a domain and a subdomain configured for different languages with the 'culture and hostnames' options.

    Dutch Homepage (nl-NL)
     - articles
      - article1
      - article2 

    EnglishHomepage (en-US
     - articles
      - article1
      - article2 

    How would I get the language code for a node/item/publishablecontent ?

  • julius 107 posts 289 karma points
    Oct 09, 2013 @ 22:21
    julius
    102

    I already found the solution here: http://our.umbraco.org/forum/developers/razor/43044-Get-language-in-Razor

    var currentHomePage = CurrentPage.AncestorOrSelf(1);
    var language = Domain.GetDomainsById(currentHomePage.Id)[0].Language;
  • Yakov Lebski 591 posts 2346 karma points
    Oct 28, 2013 @ 21:36
    Yakov Lebski
    1

    Hello

    It's work fine when we have domain on node,

    I have only culture defined on node without domain.

    And ideas how can I get only node culture?

  • Murray Roke 503 posts 966 karma points c-trib
    Dec 03, 2014 @ 21:32
    Murray Roke
    0

    Yes I don't care about the domain, I want the language regardless of whether the domain is set. (nb: I don't need it for the current page, I want to build a list of hreflang links)

  • Calle Bjernekull 28 posts 103 karma points
    Apr 16, 2015 @ 11:12
    Calle Bjernekull
    0

    I've posted a solution that works with Umbraco 7.2.4 here: https://our.umbraco.org/forum/developers/razor/43044-Get-language-in-Razor?p=1 In the case if you don't use separate domains for different langauges.

    It might work in 6 as well

    public static CultureInfo GetCulture(IPublishedContent content)
    {
    List<IPublishedContent> ancestors = content.Ancestors().ToList();
    Domain[] domains = Domain.GetDomains(true).ToArray<Domain>();
    foreach(IPublishedContent cnt in ancestors)
    {
    Domain nodeDomain = domains.Where(d => d.RootNodeId == cnt.Id).FirstOrDefault();
    if(nodeDomain != null)
    return new CultureInfo(nodeDomain.Language.CultureAlias);
    }
    return new CultureInfo(domains.First().Language.CultureAlias);
    }

     

Please Sign in or register to post replies

Write your reply to:

Draft