Reputation: 804
I have a site which uses EpiServer CMS 7.
I have a problem with the language of content which is returned after ajax call. For example, on some page I have a link, after clicking on it the AJAX-request will be sent to the server and content will be returned and inserted in special container. I have following url for AJAX request:
var urlStr= "/Folder1/Ajax/AddSomething.aspx?id=53&epslanguage=en&";
This link always contains the CORRECT language in "epslanguage" parameter. But content, which is returned after ajax call, is always in the default language(Swedish).
I have tried to debug and found that on AddSomething.aspx page I have following globalization settings:
System.Globalization.CultureInfo.CurrentUICulture == "sv";
System.Threading.Thread.CurrentThread.CurrentUICulture == "sv";
EPiServer.Globalization.ContentLanguage.PreferredCulture == "en";
Question: how can we set the correct language for the page content? As I understand, EpiServer knows the correct language, but still use "sv" when I call method
EPiServer.Core.LanguageManager.Instance.Translate(string str);
Thank you all in advance for the help.
Upvotes: 3
Views: 1121
Reputation: 804
I found the possible solution.
I have overridden InitializeCulture() method in the base class(for ajax pages) and used following code:
protected override void InitializeCulture()
{
base.InitializeCulture();
Thread.CurrentThread.CurrentUICulture = EPiServer.Globalization.ContentLanguage.PreferredCulture;
Thread.CurrentThread.CurrentCulture = EPiServer.Globalization.ContentLanguage.PreferredCulture;
}
Upvotes: 3