I have the following case. I have a lot of surface controllers with actions being called from Ajax.BeginForm requests. The actions returns a message depending on the logical procedure and these messages are from a another class library dll in which i had add resources for all the languages in order to use them globally within all my project . Unfortunately i was expecting to get the message in the culture that umbraco home page has been setup in the "Culture and Hostnames" section (the site is multilanguage and i am using the Culture and Hostnames settings for each home page).
Can anyone help me and inform me why is this happing? I tried to add in the webconfig the Globalization section with auto:
As i had read in another discussion, on application start, umbraco sets the CurrentCulture and the CurrectUICulture in the home page culture but judging from the behavior of the class library with the resources which returns always the en culture, i believe that this is not happening or something is not working very well. Am i correct or i am loosing something? Can anyone advice me how to resolve that issue because i am talking for a live production environment.
I just update the code in order to cover the possibility that someone has not enter extra domains in the root node on the action "Culture and Hostnames" and instead had set only the language on the root node. So i changed the code as following:
>
private void TrySetCulture()
{
try
{
string domain = System.Web.HttpContext.Current.Request.Url.Host; // host only
if (TrySetCulture(domain)) return;
domain = System.Web.HttpContext.Current.Request.Url.Authority; // host with port
if (TrySetCulture(domain))
return;
else
{
Node currentHome = CurrentHome;
if (TrySetCulture(string.Empty, currentHome.Id)) return;
}
}
catch
{ }
}
private bool TrySetCulture(string domain, int? nodeId = null)
{
if (!string.IsNullOrWhiteSpace(domain))
{
var uDomain = Domain.GetDomain(domain);
if (uDomain == null) return false;
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(uDomain.Language.CultureAlias);
return true;
}
else if (nodeId.HasValue)
{
var uDomain = Domain.GetDomainsById(nodeId.Value, true);
if (uDomain == null || (uDomain != null && !uDomain.Any())) return false;
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(uDomain[0].Language.CultureAlias);
return true;
}
return false;
}
private static Node _currentHome = null;
private Node CurrentHome
{
get
{
Node currentNode = umbraco.uQuery.GetCurrentNode();
if (null == _currentHome || (null != _currentHome && null != currentNode && _currentHome.Id != int.Parse(currentNode.Path.Split(',')[1])))
{
_currentHome = new Node(int.Parse(currentNode.Path.Split(',')[1]));
}
return _currentHome;
}
}
Custom Resources - load always the en-US language
Hi,
I have the following case. I have a lot of surface controllers with actions being called from Ajax.BeginForm requests. The actions returns a message depending on the logical procedure and these messages are from a another class library dll in which i had add resources for all the languages in order to use them globally within all my project . Unfortunately i was expecting to get the message in the culture that umbraco home page has been setup in the "Culture and Hostnames" section (the site is multilanguage and i am using the Culture and Hostnames settings for each home page).
Can anyone help me and inform me why is this happing? I tried to add in the webconfig the Globalization section with auto:
As i had read in another discussion, on application start, umbraco sets the CurrentCulture and the CurrectUICulture in the home page culture but judging from the behavior of the class library with the resources which returns always the en culture, i believe that this is not happening or something is not working very well. Am i correct or i am loosing something? Can anyone advice me how to resolve that issue because i am talking for a live production environment.
Regards
Thomas
I find a solution to my problem extending the solution provided in the topic for maintaining current culture across threads.
I just update the code in order to cover the possibility that someone has not enter extra domains in the root node on the action "Culture and Hostnames" and instead had set only the language on the root node. So i changed the code as following:
>
is working on a reply...