1 out of 2 rated this helpful - Rate this topic

How to: Add Resources to a Silverlight-based Application

Silverlight

This topic explains how you can use Visual Studio to add localized resource files, define the default culture, and specify supported cultures for your application.

To add resources to your application

  1. Determine the default culture for your application. It should be region-neutral. For example, "en" represents the region-neutral English language and "ru" represents the region-neutral Russian language.

  2. Add a resource to your Visual Studio project to hold the default culture's resources:

    1. In Solution Explorer, right-click the project name, point to Add, and then click New Item.

    2. In the Add New Item dialog box, under Templates, click Resources File and assign the resource file a meaningful name, such as "StringLibrary" for a resource file that contains string resources.

    3. Add the appropriate resources to it.

  3. Add one resource file to your project for each region-neutral culture or specific culture that your application supports by repeating step 2 for each culture. Name each resource file by using the root name of the resource file for the default culture, followed by a period and the culture name. (See CultureInfo for a list of region-neutral and specific culture names supported by the .NET Framework for Silverlight.) For example, if the default culture's resource file is named StringLibrary.resx, an application that has localized German language resources might have resource files named StringLibrary.de.resx and StringLibrary.de-DE.resx. Note that all satellite assemblies should be added to the same project. During the compilation process, Visual Studio includes the default culture's resource file in your application's main assembly, and it automatically creates separate assemblies for each region-neutral and specific culture for which you create a resource file.

  4. Define the default culture for your application:

    1. In Solution Explorer, right-click the project name, point to Application, and then click Assembly Information.

    2. In the Neutral Language list, select the default culture, which should be a region-neutral language, such as "en", "fr", "es", or "ru". This modifies the application's assembly information file (either AssemblyInfo.vb or AssemblyInfo.cs), by adding a NeutralResourcesLanguageAttribute attribute that defines the name of the default culture.

  5. In Solution Explorer, right-click the project name, and then click Unload Project to close the project while leaving the project icon visible.

  6. In Solution Explorer, right-click the project name, and then click Edit.

    The project file opens in the Visual Studio XML Editor.

  7. In the project file, add the names of the region-neutral and specific cultures whose satellite assemblies your application has created to the <SupportedCultures> tag. If your application supports multiple cultures, use a semicolon (;) to separate their names. This list of cultures should not include your application's default culture. For example, a <SupportedCultures> tag for an application whose default culture is English ("en") and that supports the English - United States ("en-US"), French ("fr"), French - France ("fr-FR"), Russian ("ru"), and Russian - Russia ("ru-RU") cultures might appear as follows:

    <SupportedCultures>en-US;fr;fr-FR;ru;ru-RU;</SupportedCultures>
    
  8. In Solution Explorer, right-click the project name, and then click Reload Project.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
naming resource file
It has come to my attention that if you are naming your resource file as suggested in : $0step3: "Name each resource file by using the root name of the resource file for the default culture, followed by a period and the culture name."$0 $0$0 $0 $0It will result in that you cannot reference/instanciate to it in your localizationstrings class.$0
Resource Files must go into Resource Folder on the Project
Visual Studio 2008 does not automatically place .resx files in the Resources folder of the project, but the ResXFileCodeGenerator class expects that is where the .resx file is, or it will not generate the source file when you try to make the exposure Public or Internal.