For anyone fighting to find an answer to this, I realised Language is now tied to Domain, as its part and parcel of the same area in the back office.
So i've used the new DomainService to get at the code.
Here's an example for those interested, you may need to do more iteration than I have...
public static string GetLanguage(int pageId)
{
try
{
// set default
var languageCode = "en-GB";
// try getting domain mappings for current page
IEnumerable<IDomain> currentPageDomains = ApplicationContext.Current.Services.DomainService.GetAssignedDomains(pageId, false);
if (currentPageDomains.Count() > 0)
{
// get code from first entry as multiple entries will always have the same language code
languageCode = currentPageDomains.FirstOrDefault().LanguageIsoCode;
}
else
{
// if no domain mapping for currentPage, navigate to root node and get language code
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var currentPage = umbracoHelper.TypedContent(pageId);
var rootPageId = currentPage.AncestorOrSelf(1).Id;
IEnumerable<IDomain> rootPageDomains = ApplicationContext.Current.Services.DomainService.GetAssignedDomains(rootPageId, false);
languageCode = rootPageDomains.FirstOrDefault().LanguageIsoCode;
}
return languageCode;
}
catch (Exception)
{
return "en-GB";
}
}
Get Language code for a page with Umbraco Public methods
I'm finding it very difficult to find any non-deprecated API that will provide me with the language code (inherited) for a given pageId.
Cannot find anything in IPublishedContent content or through any of the helpers.
I managed to find .Language in the ContentService but despite being apparently implemented in v6 its marked as deprecated!
The LocalizationService just seems to be a get/setAll in the system rather than whats applied to the nodes themselves.
Can anyone shed any light? Should I just use a vanilla c# method via HttpContext?
Thanks
Martin
Hello all Umbracians.
For anyone fighting to find an answer to this, I realised Language is now tied to Domain, as its part and parcel of the same area in the back office.
So i've used the new DomainService to get at the code.
Here's an example for those interested, you may need to do more iteration than I have...
is working on a reply...