Created
March 10, 2017 08:46
-
-
Save mattbrailsford/f0e23ca20ff7e96ed8fce625be708451 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class PublishedContentExtensions | |
{ | |
public static string GetLanguage(this IPublishedContent content, bool recursive = false) | |
{ | |
try | |
{ | |
var db = ApplicationContext.Current.DatabaseContext.Database; | |
var sql = "SELECT [languageISOCode] FROM [umbracoLanguage] JOIN [umbracoDomains] ON [umbracoDomains].[domainDefaultLanguage] = [umbracoLanguage].[id] WHERE [umbracoDomains].[domainRootStructureID] = @0"; | |
var cultureCode = db.ExecuteScalar<string>(sql, content.Id); | |
if (!cultureCode.IsNullOrWhiteSpace() || !recursive || content.Parent == null) | |
return cultureCode; | |
} | |
catch (System.ComponentModel.Win32Exception ex) | |
{ | |
LogHelper.Error<IPublishedContent>(string.Format("GetLanguage ({0})", content.DocumentTypeAlias), ex); | |
} | |
return recursive ? content.Parent.GetLanguage(true) : null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment