Localization EpiServer for AJAX Pages

I have a website that uses EpiServer CMS 7.

I have a problem with the content language that is returned after ajax call. For example, on some page I have a link, after clicking on it an AJAX request will be sent to the server, and the content will be returned and inserted into a special container. I have the following url for an AJAX request:

var urlStr= "/Folder1/Ajax/AddSomething.aspx?id=53&epslanguage=en&";

This link always contains the CORRECT language in the "epslanguage" parameter. But the content that comes back after the ajax call is always in the default language (Swedish).

I tried to debug and found that on the AddSomething.aspx page I have the following globalization settings:

System.Globalization.CultureInfo.CurrentUICulture == "sv";
System.Threading.Thread.CurrentThread.CurrentUICulture == "sv";
EPiServer.Globalization.ContentLanguage.PreferredCulture == "en";

Question: how to set the correct language for page content? As far as I understand, EpiServer knows the correct language, but still uses "sv" when I call the method

EPiServer.Core.LanguageManager.Instance.Translate(string str);

Thank you all for your help.

+3
source share
1 answer

I found a possible solution .

I overridden the InitializeCulture () method in the base class (for ajax pages) and used the following code:

protected override void InitializeCulture() 
{
    base.InitializeCulture();

    Thread.CurrentThread.CurrentUICulture = EPiServer.Globalization.ContentLanguage.PreferredCulture;
    Thread.CurrentThread.CurrentCulture = EPiServer.Globalization.ContentLanguage.PreferredCulture;
}
+3
source

All Articles