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" 
             xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>localize</Title>
    <Author>Balássy György</Author>
    <Shortcut>localize</Shortcut>
    <AlternativeShortcuts>
      <Shortcut Value="localize">asp:localize</Shortcut>
    </AlternativeShortcuts>
    <Description>
      Markup snippet for a control that contains localized text
    </Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
    <FileExtensions>
      aspx;master;ascx
    </FileExtensions>
  </Header>
  <Snippet>
    <Declarations>
      <Literal>
        <ID>key</ID>
        <ToolTip>key</ToolTip>
        <Default>key</Default>
      </Literal>
    </Declarations>
    <Code Language="html">
      <![CDATA[<asp:localize runat="server" meta:resourcekey="$key$" />$end$]]>
    </Code>
  </Snippet>
</CodeSnippet>

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

 

Technorati-címkék: ,

2 thoughts on “Creating an asp:Localize snippet for Visual Studio

  1. Terry J

    Thanks for the article and for the code. It’s forward thinking programmers and coders like you that we rely on to make our sites better. Very insightful.

    Reply

Leave a reply to Balássy György Cancel reply