Daily Archives: October 5, 2012

Creating an asp:Localize snippet for Visual Studio

In one of our projects we currently working on localization, in which we migrate the static texts from ASPX pages to resx files. We use asp:Localize controls to display the texts from the resource files. The Localize is essentially a Literal control, it derives from Literal without adding any new functionality to it, beside the fact that its name makes its usage more obvious in the markup.

Creating Localize controls are quite tedious, therefore after a while I created a code snippet, so now I can quickly insert the tag with TAB-TAB, and all I have to type is the name of the resource key. Here is the code, just paste it into .snippet file and then copy the file to the C:\Program Files (x86)\Microsoft Visual Studio 10.0\Web\Snippets\HTML\1033\ASP.NET folder, Visual Studio will recognize it:

<CodeSnippet Format="1.1.0" 
    <Author>Balássy György</Author>
      <Shortcut Value="localize">asp:localize</Shortcut>
      Markup snippet for a control that contains localized text
    <Code Language="html">
      <![CDATA[<asp:localize runat="server" meta:resourcekey="$key$" />$end$]]>

Creating a snippet like this takes only 5 minutes, but makes your life much easier.


Technorati-címkék: ,