다음을 통해 공유


How to: Localize Feature Attributes in Sandboxed Solutions

This topic explains how to localize the properties of a Feature, such as its title and description, in a sandboxed solution.

Applies to: SharePoint Foundation 2010

The process of localizing the properties of a Feature that is deployed in a sandboxed solution, such as its title and description, differs in some ways from the process that is used for farm solutions.

Note

This topic assumes that you have performed the procedures in Preparing to Create Localized SharePoint Solutions. This topic assumes that English and Spanish are available on your development farm, but you can substitute a different pair of languages.

Localization of Feature Properties in Sandboxed Solutions

The basic properties of every SharePoint Feature are defined in a Features.xml file. (Within a Microsoft Visual Studio SharePoint project, the extension of the file is .feature, instead of .xml.) There can be custom properties defined in the file, but the built-in properties are specified as attributes of the Feature element. Some of these attributes, such as Title and Description, can be localized. Doing so ensures that in the Features gallery of a site collection or website, your Feature will have a title and description that is appropriate for the language of the site collection or website. For more information about Features and Feature markup in SharePoint, see Using Features in SharePoint Foundation and Feature.xml Files.

Sandboxed solutions cannot deploy files to the file system of the servers, but there is a way to use localized strings in .resx files that are deployed to the content database. The procedures in this topic show how to use this technique.

To create the resource files

  1. In Solution Explorer, right-click the Feature name, and select Add Feature Resource.

  2. In the Add Resource dialog box, select Invariant Language (Invariant Country), and then click OK. A Resource.resx file is added to the Feature's folder in Solution Explorer, and the file is opened in the Visual Studio Resource Editor.

    When edited, this "invariant language" file contains the Feature title and description that will be used in the Feature gallery on all sites in languages for which you are not going to be providing a localized version of strings. So the language used for the strings in this file should be the language that is most likely to be a second language of people using SharePoint in a language for which you are not providing a translation of your strings. Traditionally, English is used for this purpose, but there may be exceptions. For example, if your Feature is primarily going to be used in countries that were formerly French colonies, French may be a more common second language of the users than English. The continuing example in this topic uses English as the invariant language.

  3. In the Name column of the top row in the Resource Editor, enter FeatureTitle.

  4. In the Value column, enter an appropriate title. For the continuing example, use Localized Sandboxed Solution.

  5. In the next row, use FeatureDescription as the Name and an appropriate description as the Value. For the continuing example, use This is a Localized Solution..

  6. Save the file.

  7. Add another resource file to the Feature as you did before, but select a particular language instead of Invariant Language (Invariant Country). For the continuing example, use Spanish (Spain). A Resource.LL-CC.resx file (where LL is a language code and CC is a country or culture code) is added to the Feature's folder in Solution Explorer, and the file is opened in the Visual Studio Resource Editor.

  8. Using the Resource Editor, copy all the rows from Resource.resx, and paste them into the new Resource.LL-CC.resx file.

  9. In the Resource.LL-CC.resx file, replace the Value cells with translated versions of the string values. For the continuing example, use Solución aislada localizada for the FeatureTitle and Esto es una solución localizada. for the FeatureDescription.

  10. Save the new file.

  11. Repeat the last three steps for each foreign language. For the running example, add one more for English (United States).

    Note

    When the language-specific resource file is for the same language that you are using as your invariant language, you can copy the rows without changing the values of the strings. In many situations, it is not necessary to have a language-specific file for the same language that is used in the resource file for the invariant language, especially when the only resources in the files are strings. But resource files can contain images, icons, files and other kinds of resources too. Sometimes, you need the invariant language resource file to use an image or other resource that is different from the corresponding resource in any of the language-specific files.

To reference the resource files in the Features.xml file

  1. In Solution Explorer, double-click the .feature file to open it.

  2. Switch from the Feature Designer view to the raw markup view by clicking the Manifest tab at the bottom of the designer.

  3. Click the + next to Edit Options to expand the Edit Options part of the view. A manifest template opens in an editable text box.

  4. Add Title="" and Description="" attributes to the Feature element.

  5. For the value of the Title attribute, use $Resources:FeatureTitle. For the value of the Description attribute, use $Resources:FeatureDescription. (Notice that the resource file name is not used in these values.)

  6. Save the file.

    Note

    The title of the Feature in the Feature Designer does not change.

To test the localization

  1. Build and package the solution.

  2. Deploy the solution package to the Solutions Gallery of a site collection that was created in one of the foreign languages and activate the solution.

  3. Navigate to the Site Settings page, and open the Features gallery of either the site collection or the root website depending on whether the scope of your Feature is Site or Web. You should see your Feature listed with a title and description that you gave it for the language of the site collection.

  4. Repeat the last two steps for every foreign language for which you created a language-specific resource file.

  5. Repeat the deployment and activation on some foreign language site collection for which you did not create a language-specific resource file. You should see your Feature listed with the title and description that you gave it in the language invariant resource file.

See Also

Concepts

Sandboxed Solutions Architecture in SharePoint 2010

Other Resources

Localization of Sandboxed Solutions in SharePoint 2010

Sandboxed Solutions Resource Center | SharePoint 2010

SharePoint Developer Team Blog

SharePoint Developer Center