I'm having the exact same problem. I can't find a way to retrieve a node's language/culture when no domain has been set. I tried the usual
umbraco.library.GetCurrentDomains(pageId)
but without setting a domain, the above gives me an array with no items.
Then I tried
contentService.GetById(pageId).Language
as the OP did, and got null. So how can we retrieve that piece of information?
For the time being, I've created a hacky workaround, I added a dummy hostname to each language root node, so that the GetCurrentDomains method returns a non-empty array. But this is definitely hacky. Ideally, one should be able to retrieve the "Language" setting in the "Culture" pane in the "Culture and hostnames" popup somehow.
The workaround I posted earlier actually breaks NiceUrl. It seems that NiceUrl picks up the domain entered and prepends it - I can't seem to find a way to remove the domain prefix. Keeping it makes debugging a project next to impossible, since all links generated by NiceUrl are not "localhost".
Any solution to this? The issue is still persisting in 6.1.5 and I can't seem to find a valid workaround. The real question is, how do we retrieve a specific node's Culture, as set from within the umbraco interface, when no domain has been set?
Have you logged this as an issue on http://issues.umbraco.org? If you log it there, there's a better chance of it getting seen by one of the core team than on here! I think Stephan (@zpqrtbnk on Twitter) is possibly the best person to answer this one.......
I am not using domains and implemented this workaround:
Looking at the database struction (SQL CE in my instance), to find the language of the root node, I noticied I could start in the UmbracoDomains table to identify the ID of a root node. This record also has a domainDefaultLanguage which point to a language in the umbracoLanguage table.
Thus, if you have a list of root node Ids, you can create a method that looks up the language for each root node.
If a root ID was 1054, you could write the T-SQL like:
select ul.languageISOCode from umbracoDomains ud
join umbracoLanguage ul on ud.domainDefaultLanguage = ul.id
where ud.DomainRootStructureID = 1054
In my project, I've created a basic method that uses SqlCeConnection and pipes in the T-SQL command:
public static string GetCultureAliasForRootNode(int rootNodeId) {
{
var connectionString = ConfigurationManager.ConnectionStrings["myUmbracoDSN"].ConnectionString;
string cultureAlias;
using (var connection = new SqlCeConnection(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";
Language = null on contentService.GetById()
Hi,
I am using the new v6 contentService on a umbraco 6.1.2
When I do
var nodeLanguage = contentService.GetById(1083).Language;
I always get back a null value. I am pretty sure the "culture" is set on this node.
What is going wrong?
Hey Damiaan, did you set the culture and the hostname correctly?
Yes culture was set correctly. In v6 you are not obligated to set a domain name when setting the Culture. So no domain name was set.
I'm having the exact same problem. I can't find a way to retrieve a node's language/culture when no domain has been set. I tried the usual
umbraco.library.GetCurrentDomains(pageId)
but without setting a domain, the above gives me an array with no items.
Then I tried
as the OP did, and got null. So how can we retrieve that piece of information?
For the time being, I've created a hacky workaround, I added a dummy hostname to each language root node, so that the GetCurrentDomains method returns a non-empty array. But this is definitely hacky. Ideally, one should be able to retrieve the "Language" setting in the "Culture" pane in the "Culture and hostnames" popup somehow.
Quick update:
The workaround I posted earlier actually breaks NiceUrl. It seems that NiceUrl picks up the domain entered and prepends it - I can't seem to find a way to remove the domain prefix. Keeping it makes debugging a project next to impossible, since all links generated by NiceUrl are not "localhost".
Any solution to this? The issue is still persisting in 6.1.5 and I can't seem to find a valid workaround. The real question is, how do we retrieve a specific node's Culture, as set from within the umbraco interface, when no domain has been set?
i also have the same issue. Anyone find a nice workaround? is this a know issue on umbraco?
Well, it seems that it's done in 6.1.6. The Entity property of the event argument in the Created handler seems to have a numeric Id.
Sorry, wrongfully posted in this thread for a reply to another thread.
No, the issue is still persisting in 6.1.6.
Have you logged this as an issue on http://issues.umbraco.org? If you log it there, there's a better chance of it getting seen by one of the core team than on here! I think Stephan (@zpqrtbnk on Twitter) is possibly the best person to answer this one.......
Just submitted this as http://issues.umbraco.org/issue/U4-3753 Thanks for the heads up.
Still not fixed in version 7.2.1
I commented on the issue. Hoping it will get some love soon. If not, I'm considering tackling it myself and submitting a pull request.
I am not using domains and implemented this workaround:
Looking at the database struction (SQL CE in my instance), to find the language of the root node, I noticied I could start in the UmbracoDomains table to identify the ID of a root node. This record also has a domainDefaultLanguage which point to a language in the umbracoLanguage table.
Thus, if you have a list of root node Ids, you can create a method that looks up the language for each root node.
If a root ID was 1054, you could write the T-SQL like:
select ul.languageISOCode from umbracoDomains ud
join umbracoLanguage ul on ud.domainDefaultLanguage = ul.id
where ud.DomainRootStructureID = 1054
In my project, I've created a basic method that uses SqlCeConnection and pipes in the T-SQL command:
public static string GetCultureAliasForRootNode(int rootNodeId) {
{
var connectionString = ConfigurationManager.ConnectionStrings["myUmbracoDSN"].ConnectionString;
string cultureAlias;
using (var connection = new SqlCeConnection(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", rootNodeId);
cultureAlias = command.ExecuteScalar().ToString();
}
return cultureAlias;
}
Using 'Microsoft.SqlServer.Compact 4.0.8876.1' nuget package to access the SQLCE database.
Thanks Warren.
That would be a way to do it, however I prefer the Umbraco way (i.e. go through the API wherever possible).
In any case, this issue has been addressed in 7.2.3 onwards.
Cheers,
Yiannis
I'd also prefer to use the Umbraco API, but I'm using v7.2.4 and it doesn't work as expected.
This is still an outstanding issue - when will this be fixed?
is working on a reply...