Localization

  • Thread starter Adrián E. Córdoba
  • Start date
A

Adrián E. Córdoba

I was learning how to use localization in the web sites by reading
"Walkthrough: Using Resources for Localization in ASP.NET" from the
Help in VS2005.
This Walkthrough talk about localization of controls in Design view.
But, how can I localize the controls I add to the web site
programmatically by coding in Visual C#?

Thank you in advance.
 
A

Alberto Poblacion

Adrián E. Córdoba said:
I was learning how to use localization in the web sites by reading
"Walkthrough: Using Resources for Localization in ASP.NET" from the
Help in VS2005.
This Walkthrough talk about localization of controls in Design view.
But, how can I localize the controls I add to the web site
programmatically by coding in Visual C#?

When you are programmatically creating the control, instead of assigning
a fixed text to the properties, you extract the text from the Resources. In
that way it gets translated in the same way as the contents that you create
in the designer. For instance:

Label lbl = new Label();
lbl.Text = GetLocalResourceObject("myLabel.Text").ToString();
theContainer.Contros.Add(lbl);

The previous example requires you to manually add the "myLabel.Text"
resource to the local resource file for the page. If you prefer to use
global resources you can do

lbl.Text = Resources.WebResource.TheKey;

or

lbl.Text = (string)GetGlobalResourceObject("WebResource", "TheKey");

both of which assume that you have added "TheKey" to the WebResource.resx
file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top