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
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()
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
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.
/// <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 ?? "";
}
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.
How would we get it now?
Do we have to check current.Thread.CultureInfo or is there a simplier way?
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.
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
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()
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
Hi Luke.
Your link gave me a better insight in what's going on, so that was very helpful.
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.
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.
Hi Bo, I use this snippet to get the current culture
without arguments.
Hi Giuseppe.
That seems to work.
Before your answer i made a method that also seems to work, but i rather use the IPublishedContent.GetCultureFromDomains()
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?
Hi Dimitri.
Model.Cultures
should do it.Thanks. You saved me some time here.
None of that works anymore. UmbracoContext has become Current.UmbracoContext, and DomainUtilities.GetCultureFromDomains is now an internal method.
UPD
Here is my extension method to get old-school
CultureInfo
object like it was in Umbraco 7.Let me know if you know the better way
Thank you Dmitriy, this allowed me to save time and keep the current architecture for our subnavigation:
is working on a reply...