Copied to clipboard

Flag this post as spam?

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


  • Neil Tootell 73 posts 118 karma points
    Aug 10, 2015 @ 14:22
    Neil Tootell
    1

    How to get the culture of a node by ID

    Hi all,

    I'm on a 6.2.4 version of Umbraco and I'm doing some funky navigation elements.

    Part of it is to create a language switch link.

    For that I'm looping through the root nodes in the site, trying to get their Language setting. The problem I'm having is the culture always comes back as the current culture I'm in rather that being able to ask Umbraco for the culture of a specific node.

    I don't and can't have domains set in the root nodes, but I do have languages set.

    This is the closest thing I can find, but it seems to only run from the current context.

    CultureInfo.CurrentCulture.Name
    

    Any help would be much appreciated. So how do I get the language by NodeID?

    Neil

  • Per Olsson 47 posts 307 karma points
    Aug 10, 2015 @ 14:52
    Per Olsson
    0

    The .Language property should do it. It will return the country code for the selected language, e.g. en-US.

    https://our.umbraco.org/documentation/Reference/Management-v6/Models/Content

    enter image description here

  • Neil Tootell 73 posts 118 karma points
    Aug 10, 2015 @ 16:00
    Neil Tootell
    0

    Hi Per,

    Thanks for the response - unfortunately the .language feature has not been implemented into 6.2.4.

    Do you know of any old-school methods that may work??

    Thanks

    Neil

  • Neil Tootell 73 posts 118 karma points
    Sep 07, 2015 @ 11:01
    Neil Tootell
    0

    To solve this on 6.2.4, I had to make sure the root site node was named correctly after a valid language culture name, and invoke a the CultureInfo class.

    Code here on how to do it, though it does rely on Umbraco users correctly naming the root node.

    Per - thanks for your responses, it would have been nice if the ".Language" function was implemented in v6.2.4 :(

     var languagePrefix = siteRootNode.Name.Split('-').FirstOrDefault();
                            var ci = new CultureInfo(siteRootNode.Name);
                            var siteTitle = "view this site in " + ci.DisplayName;
    

    Might help others who have the same challenge.

Please Sign in or register to post replies

Write your reply to:

Draft