Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This topic applies to Windows Workflow Foundation 4 (WF4).
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
In Visual Studio 2010, right-click your project in Solution Explorer and select Add…, New Item….
Select Resources File and name the file ErrorResources.resx. Click Add.
Open the resource file. Add a new entry with a Name of ErrorString and a Value of "The activity is not valid."
Add the following
usingstatements to your class.using System.Reflection; using System.Resources;Create a resource manager in your project.
ResourceManager ErrorManager; ... ErrorManager = new ResourceManager("MyNamespace.ErrorResources", Assembly.GetExecutingAssembly());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 **
//---------------------------------------------
metadata.AddValidationError(SR.TypeMismatchForAssign(
this.Value.ArgumentType,
this.To.ArgumentType,
this.DisplayName));
}
}
}