Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
Created March 10, 2017 08:46
Show Gist options
  • Save mattbrailsford/f0e23ca20ff7e96ed8fce625be708451 to your computer and use it in GitHub Desktop.
Save mattbrailsford/f0e23ca20ff7e96ed8fce625be708451 to your computer and use it in GitHub Desktop.
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