I set the "culture and hostname" on a per page basis (not on the root domain, because I can't)
I want to retrieve a CultureInfo object for an individual node (IPublishedContent) like "Some French Page" and for it to return me all the good stuff like isocodes etc "fr-FR".
but actually, I wanted to do this on the parent page and
@foreach (IPublishedContent childPage in Model.Content.Children) {
<p>@childPage.CurrentCulture</p> // doesn't work
}
I've also seen posts that suggest
@foreach (IPublishedContent childPage in Model.Content.Children)
{
var childContent = ApplicationContext.Current.Services.ContentService.GetById(childPage.Id);
<p>@childContent.Language</p> // not implemented
}
In V7 theres an extension GetCulture() for IContent and IPublishedContent
But can't find the right way to get the culture of a child page (IPublishedContent) directly in 6.2.5
public static class LanguageHelper
{
public static ILanguage GetLanguage(this IPublishedContent node)
{
// guard; no node
if (node == null) return null;
// hit the db and try to find isoCode
var connectionString = ConfigurationManager.ConnectionStrings["yourConnectionString"].ConnectionString;
string isoCode;
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
var command = connection.CreateCommand();
command.CommandText = "select ul.languageISOCode from umbracoDomains ud join umbracoLanguage ul on ud.domainDefaultLanguage = ul.id where ud.DomainRootStructureID = @rootNodeId";
command.Parameters.AddWithValue("@rootNodeId", node.Id);
isoCode = Convert.ToString(command.ExecuteScalar());
}
// guard; no iso code found
if (string.IsNullOrEmpty(isoCode)) return null;
// hit the LocalizationService to actually return the language
return ApplicationContext.Current.Services.LocalizationService.GetLanguageByIsoCode(isoCode);
}
}
Now I get the good stuff (provided you've set the culture and hostname explicitly on the node you want):-)
Get Culture of IPublishedContent v6.2.5
Hi
My site structure is like so;
I set the "culture and hostname" on a per page basis (not on the root domain, because I can't)
I want to retrieve a CultureInfo object for an individual node (IPublishedContent) like "Some French Page" and for it to return me all the good stuff like isocodes etc "fr-FR".
How do I do this in v6.2.5?
Comment author was deleted
You should be able to use the standard .net stuff like Thread.CurrentThread.CurrentCulture
Yep, if I'm on the page I can simply call;
but actually, I wanted to do this on the parent page and
I've also seen posts that suggest
In V7 theres an extension
GetCulture()
forIContent
andIPublishedContent
But can't find the right way to get the culture of a child page (IPublishedContent) directly in 6.2.5
So, I found
Which helped me create a helper method;
Now I get the good stuff (provided you've set the culture and hostname explicitly on the node you want):-)
Used sparingly with caching and suitable null checks, this is an OK solution.
is working on a reply...