Export (0) Print
Expand All

Activity Localization

When workflow applications and components have the potential to be localized into other cultures and languages, resource strings should be used so that they can be localized without recompiling.

Activity Localization

As with all applications that must be localized (released in different versions for different languages and cultures), any strings that are displayed to the user should not be put directly in code, but rather stored in a resource file. The strings can then be accessed through GetResourceString. If you are developing a component that is distributed in several languages, you also want to use resource strings for activity validation messages, user-defined tracking data, tracing messages, and error messages as well.

The following exercise demonstrates how to use a resource file.

Using resource files for localized strings

  1. In Visual Studio 2010, right-click your project in Solution Explorer and select Add…, New Item….

  2. Select Resources File and name the file ErrorResources.resx. Click Add.

  3. Open the resource file. Add a new entry with a Name of ErrorString and a Value of "The activity is not valid."

  4. Add the following using statements to your class.

    using System.Reflection;
    using System.Resources;
  5. Create a resource manager in your project.

    ResourceManager ErrorManager;
    ErrorManager = new ResourceManager("MyNamespace.ErrorResources", Assembly.GetExecutingAssembly()); 
  6. Get the string from the resource manager where it is required.

    String errorMessage = ErrorManager.GetString("ErrorString");

The following code sample demonstrates how to utilize localized strings in the CacheMetadata method.

       protected override void CacheMetadata(CodeActivityMetadata metadata)
          // rest of the code elided for brevity
            if (this.Value != null && this.To != null)
                if (!TypeHelper.AreTypesCompatible(this.Value.ArgumentType, this.To.ArgumentType))
// ** SR.TypeMismatchForAssign will fetch the string from the resource manager **

Build Date:

© 2014 Microsoft