Copied to clipboard

Flag this post as spam?

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

  • Bo Jacobsen 294 posts 1282 karma points
    Jul 11, 2019 @ 15:08
    Bo Jacobsen

    How to get current culture from IpublishedContent in umbraco 8

    Hi all.

    Just upgraded to Umbraco 8.1.0 from 8.0.2 and have to change our code to work with the breaking changes.

    Before we could get the current PublishedCultureInfo by the IPublishedContent interface like this.

    using Umbraco.Web;

    How would we get it now?

    Do we have to check current.Thread.CultureInfo or is there a simplier way?

  • Luke Hook 38 posts 151 karma points
    Jul 11, 2019 @ 15:44
    Luke Hook

    Hi there,

    Looking at some of the recent changes in 8.1 there have been a number of methods removed from IPublishedContent that break a number of things.

    Check out this link

    Paying attention to Stephens comment further down that gives a summary of changes.

    An extract from which is here.

    Culture: content.Cultures now returns a collection of string representing the available cultures, and content.GetCulture(...) is gone, the proper way to get the culture date is content.CultureDate(string culture = null)

    Not sure if that fully answers your question or not but should hopefully helps. IMO this changes should have been documented better in the release notes. I've seen number of posts the last couple of days regarding these changes and the information only exists in those comments quite for down the string of the change request

  • Bo Jacobsen 294 posts 1282 karma points
    Jul 11, 2019 @ 18:34
    Bo Jacobsen

    Hi Luke.

    IPublishedContent.CultureDate(string culture = null) returning a DateTime and not a PublishedCultureInfo.

    If you do not set a culture, then the function try to find it this way. And maybe thats the new way to get the current Culture instead of IPublishedContent.GetCulture()

  • Luke Hook 38 posts 151 karma points
    Jul 11, 2019 @ 18:37
    Luke Hook

    Hi Bo,

    Sorry yes there didn't appear to be a new way of getting the current Culture. I was just highlighting where this information was surrounding it's removal in the release notes. Seems strange to remove it completely without a solid alternative

  • Bo Jacobsen 294 posts 1282 karma points
    Jul 11, 2019 @ 18:44
    Bo Jacobsen

    Hi Luke.

    Your link gave me a better insight in what's going on, so that was very helpful.

  • Bryna 66 posts 228 karma points
    Jul 11, 2019 @ 21:48

    I think the Properties now take culture as an argument.


    It is a bit more intuitive provided one isn't set in their ways:). I think that is a fairly solid alternative.

  • Bo Jacobsen 294 posts 1282 karma points
    Jul 12, 2019 @ 05:55
    Bo Jacobsen

    Hi Bryna.

    Model.Value("customProp","es") was also possible before. But Model.Url("es") and Model.Name("es") is new.

    The weird thing is if you dont set a culture it will take the current culture. But there aint a method to get the current culture and that is what i need.

  • giuseppe 9 posts 63 karma points
    Jul 12, 2019 @ 08:21

    Hi Bo, I use this snippet to get the current culture


    without arguments.

  • Bo Jacobsen 294 posts 1282 karma points
    Jul 12, 2019 @ 08:58
    Bo Jacobsen

    Hi Giuseppe.

    That seems to work.

    /// <summary>
            /// Gets the culture assigned to a document by domains, in the context of a current Uri.
            /// </summary>
            /// <param name="content">The document.</param>
            /// <param name="current">An optional current Uri.</param>
            /// <returns>The culture assigned to the document by domains.</returns>
            /// <remarks>
            /// <para>In 1:1 multilingual setup, a document contains several cultures (there is not
            /// one document per culture), and domains, withing the context of a current Uri, assign
            /// a culture to that document.</para>
            /// </remarks>
            public static string GetCultureFromDomains(this IPublishedContent content, Uri current = null)
                var umbracoContext = UmbracoContext;
                if (umbracoContext == null)
                    throw new InvalidOperationException("A current UmbracoContext is required.");
                return DomainUtilities.GetCultureFromDomains(content.Id, content.Path, current, umbracoContext, SiteDomainHelper);

    Before your answer i made a method that also seems to work, but i rather use the IPublishedContent.GetCultureFromDomains()

    public string GetCulture()
        return Umbraco.Core.Composing.Current.VariationContextAccessor?.VariationContext?.Culture ?? "";
  • Dmitriy 135 posts 510 karma points
    Jul 12, 2019 @ 10:05

    Thank you, I was looking for that too.

    By the way, may be you know the approach to get all published cultures for current page?

  • Bo Jacobsen 294 posts 1282 karma points
    Jul 12, 2019 @ 10:15
    Bo Jacobsen

    Hi Dimitri.

    Model.Cultures should do it.

Please Sign in or register to post replies

Write your reply to: