Share via


How to: Localize ASPX Markup

ASP.NET (.aspx) pages typically use hard-coded string values. To localize these strings, replace them with expressions that reference localized resources.

Localizing ASPX Markup

To localize ASPX markup

  1. Add separate resource files: one for the default language and one for each localized language.

    If you are localizing only markup and not code, add a Global Resources File project item. If you are localizing code and markup, add a Resources File project item.

    1. To add a Global Resources File, right-click a SharePoint project item in Solution Explorer, point to Add, and then click New Item, and then select Global Resources File in the SharePoint 2010 folder.

    2. To add a Resources File, right-click a SharePoint project item in Solution Explorer, point to Add, and then click New Item, and then select Resources File in either the Visual Basic or Visual C# folder.

    Note

    Be sure to add the resource files to a SharePoint project item to enable the Deployment Type property. This property is required later in this procedure. If your solution does not have a SharePoint project item, you can add an Empty SharePoint Project and remove its default Elements.xml file.

  2. Give the default language resource file a name of your choice appended with a .resx extension, such as MyAppResources.resx. Use the same base name for each localized resource file, but add the culture ID. For example, name a German localized resource MyAppResources.de-DE.resx.

  3. Change the Deployment Type property of each resource file to AppGlobalResource to cause them to deploy to the server's App_GlobalResources folder.

  4. If you are using the resources to localize code in addition to ASPX markup, leave the Build Action property of each file as Embedded Resource. If you are using the resource files only to localize markup, you can optionally change the property value of the files to Content. For more information, see Localizing SharePoint Solutions.

  5. Open each resource file and add localized strings, using the same string IDs in each file.

  6. In the XML markup for the ASPX page or control, replace the hard-coded strings with values that use the following format:

    <%$Resources:Resource File Name, String ID%>
    

    For example, to localize the text for a label control on an application page, you would change:

    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <asp:Label ID="lbl" runat="server" Text="Label text"></asp:Label>
    </asp:Content>
    

    to

    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <asp:Label ID="lbl" runat="server" Text="<%$Resources:MyAppResources,String1%>"></asp:Label>
    </asp:Content>
    
  7. Press F5 to build and run the application.

  8. In SharePoint, change the display language from the default.

    The localized strings appear in the application. To display localized resources, the SharePoint server must have a language pack installed that matches the resource file's culture.

See Also

Tasks

How to: Localize a Feature

How to: Add a Resource File

How to: Localize Code

Concepts

Localizing SharePoint Solutions