Asp.Net General Local Resource tool for user control

asp.netlocalization

When I use the Visual Studio menu Tool -> Generate Local Resource, it changed aspx file by adding meta attributes to controls. But it doesnt do so for user controls that I have created.

For example, If I have used a control in the page

<myControl:SpecialLabelControl ID="myLabel" runat="server" Text="Localize Me!" />

I want "Localize Me!" to go in the resource file and a meta attribute added to the SpecialLabelControl.

How can I do this?

How does the tool create resource strings for built in controls automatically? Does it read an attribute of the property? How can I make the tool do the same to my control?

Best Answer

Firstly, make sure 'Text' is a publicly accessible property on your control.

Add [Localizable(true)] above the declaration, as shown in the example on this page

This will tell the IDE that this property is supposed to be picked up by resource files, and Tools -> Generate Local Resources will do the rest! EDIT - after further research I came across this article (and excerpt from a book). It seems that UserControls you created with publicly accessible properties can't be hit by the GLR tool :(

The ones I've worked on before were classes I created as '.cs' files, not user controls, I suppose.

Related Topic