Enovator
Enovator

Reputation: 13

ASP.NET Translate and Localize an WebForms App

I have a task of translating a big WebForms App (some 300 aspx pages). I will use conventional approach on translating ASP.NET apps (using Resource files) and I will use ZetaResource to make my life easy. However, I have a small issue: What can I do with free text existent in aspx code? Take this code for instance, how can I convert the text This is a List of records available in the Database into an ASP:Label server control in order to use the embedded Translation Mechanism?

<form id="form1" runat="server">
<div>
    <br />
  This is a List of records available in the Database<br />    
    <br />
    <asp:Button ID="cmdButton" runat="server" Text="Button" meta:resourcekey="cmdButtonResource1" />
</div>
</form>

Upvotes: 0

Views: 2444

Answers (2)

Rob Johnston
Rob Johnston

Reputation: 879

You have two choices for localization: explicit and implicit.

For explicit localization, you would put the text into a resource file and display it on the web page with code like the following:

<asp:Localize ID="Localize1" Runat="server" Text="<%$ Resources:LocalizedText, ListOfRecordsInDatabase%>" />

For implicit localization, the code would look like more like this:

<asp:Localize ID="Localize1" Runat="server" meta:resourcekey="LocalizeResource1" Text="This is a List of records available in the Database" />

For these one-off texts that exist only in a single page, I usually use implicit localization. For text that can exist on many pages (common labels, buttons, etc.), I use explicit.

The implicit localization resource files can even be auto-generated for you, once you put them into a server control, like <asp:Localize> or <asp:Label>.

There is a great walkthrough given on the MSDN site called, "Walkthrough: Using Resources for Localization with ASP.NET". It will tell you how to auto-generate the resource files.

Upvotes: 1

CodingYoshi
CodingYoshi

Reputation: 27049

Imagine you have a resource file named YourResource and the item you want is String1, you can just do this for free text:

<%= (YourResource.String1) %>

Upvotes: 1

Related Questions