Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use a Localize control instead of a Literal?

Tags:

I recently became aware of the System.Web.UI.WebControls.Localize control in a lab for the ASP.NET 4.0 MCTS certification course. The purpose of this control is unclear to me.

In the examples, the Literal control and the Localize control appear to be more-or-less interchangeable. Upon inspection, it appears that the Localize control inherits from Literal, but provides no additional functionality. It uses a different designer class, which appears to me to be less capable than the designer class for literals.

So, color me confused. Literals are localizable already. What is the Localize control used for? Should I use it, and under what circumstances?

like image 651
kbrimington Avatar asked Feb 25 '11 22:02

kbrimington


People also ask

Which control can you use to apply Localisation?

The Localize control is used at design time to distinguish static text that can be localized from other static text. Although the Label control allows you to apply a style to the displayed text, the Localize control does not. You can programmatically manage the text displayed in the control by setting the Literal.

How can use localize control in ASP.NET with example?

ASP.NET server control localization is the easiest of all. Once you add a server control to your page, you can simply switch your page to “Design” mode and then go to the menu “Tools”->“Generate Local Resource”. It will generate a resource string for each ASP.NET server control on the page.


1 Answers

I appreciate this has already been marked as answered, but here is another way to look at it.

<asp:Localize> is used to specify a Resource defined item, which forces the IDE to display some specified text, and still allows it to resolve at runtime, to the language of the website.

This may be useful for the development of a site where the content of the site is actually in a different language. So you would be able to be an English-speaking programmer, creating a website in Turkish, and still know what a <asp:Label> is supposed to without having to learn Turkish.

So as an example:

<asp:Localize runat="server" Text="<%$Resources : Label, Price%>">         Price </asp:Localize> 

Now, if my default Label.resx was translated into Turkish, the Labels.resx mapping would be:

Key="Price" Value="fiyat" 

At design time, the IDE would display Price (as the inner text of the <asp:Localize> element is Price) but the actual live view of the page in a web browser, would resolve to fiyat.

Therefore:

<div>    <asp:Localize runat="server"                   Text="<%$Resources : Label, Price%>">                       Price    </asp:Localize> </div> 

Becomes rendered as:

<div>fiyat</div> 

But in the IDE Designer, this would be displayed as "Price".

The difference with labels, is that <asp:Label> will resolve to fiyat in both the IDE Designer and at run-time.

like image 200
Dominic Zukiewicz Avatar answered Oct 13 '22 06:10

Dominic Zukiewicz