Question

I have a kendo single page application that I need to localize. I tried using Javascript to translate text parts, but it gets complicated when translating non HTML bits like templates (inside script tags) and properties like "data-title".

Next I tried changing the extension to .aspx and using ASP.NET resources, as in this example:

<!-- logout -->
<div id="logout" data-role="view" data-layout="layout-logout" 
    data-title="<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:TextStrings, Logout%>" />" 
    data-before-show="myproject.logout">
<div style="padding: 50px 0; text-align: center;">
<p id="lang_LoggedOut"><asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:TextStrings, Logout_Success%>" /></p>
</div>
</div>

This works to some extent, as the <% resources %> bits get replaced.

However I had to transfer login to a separate .aspx page to apply the language, after login (and discovering user culture), but before single page app load.

The login page calls the customary:

protected override void InitializeCulture()

to set the culture, and then redirects to the main app page.

As far as I can make out, the InitializeCulture is ignored, but the page is rendered with the strings from the resource files, sometimes in one language, sometimes in another.

How does ASP.NET decide what culture to apply, and how can I control that choice?

Notes:

  1. failing this, the kendo people seem to suggest having one page for each language, which rather goes against my DNRY inclinations.
  2. Code behind and inline code (<%Page%> directive) are in my experience incompatible with kendo. If I understand right page events get stolen by one another. Kendo is compatible with MVC, but I must learn MVC first, and then get resource files to work with MVC.
Was it helpful?

Solution

The short answer is yes. I have seen it work with VS2010 and IIS 7.5.

  1. The page with no code behind must have an .aspx extension.
  2. the language selection must happen on another .aspx page with code-behind. Call InitializeCulture() here
  3. from this page you must go to the main page using Server.Transfer. See: Server.Transfer Vs. Response.Redirect

Server.Transfer will keep the settings and context you set, and apply the language to the page with no code-behind while the user navigates the page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top