Help XML and Multilingual Support in Code Effects

All dynamic element names that the Rule Editor displays, such as names of all rule fields, in-rule methods, or rule actions, are defined by either the DisplayName property of the corresponding Field, Method, Action, Parent, or EnumItem attribute, or by the source object itself if you don't use those attribute classes to customize your source.

All static labels and messages, such as labels of every operator, flow, or clause element, as well as every button name, text box value, or message that you see in the Help String, are defined in a special XML document used internally by Code Effects. That document is called Help XML.

It is very likely that you will want to display all those UI elements in multiple languages if your application supports multiple cultures or uses a language other than English. It takes almost no effort to do that with Code Effects.

Source Object

If your application only needs to support a single language, all you need to do is set display names and, optionally, descriptions in the supported language for all fields, properties, and methods used in your business rules when you create your source object(s).

For applications that support multiple languages, you need to create multiple Source XML documents, one for each supported language, set the displayName and, optionally, description attributes for all fields, actions, and in-rule methods used in the document in the desired language:

When all Source XML docs are finished and saved, you need to tell Code Effects which one to load for the current user. This process can be as complicated as you want to make it, of as primitive as a single switch statement:

switch(currentCulture)
{
	case "de-DE":
		this.ruleControl.SourceXmlFile = Server.MapPath("/German/Source.config");
		break;
	case "fr-FR":
		this.ruleControl.SourceXmlFile = Server.MapPath("/French/Source.config");
		break;
	// The English doc is used by default.
	// No need to set it unless you have modified it as well.
}

You can use the RuleEditor.SourceXml property of System.Xml.XmlDocument type instead of the SourceXmlFile if you create your sources programmatically, which would help to lower IO on the server. In ASP.NET, you can improve performance even further by setting the RuleEditor.CacheSource property to True to cache your source(s) on the server. Remember to clear the cache by calling the RuleEditor.ClearCache() method prior to reloading updated source(s). The source caching feature is not provided in the MVC version of Code Effects.

Help XML

You also need a single Help XML document for each separate culture used in your application. Help XML is nothing more than a simple XML document that contains all static labels and messages used by the Rule Editor. Code Effects component includes two default English XML documents, one for data filtering and the other for business rules. The only difference between them is that the "filtering" document replaces the word rule with the word filter in all labels and messages. Code Effects component uses the "filtering" document only when the RuleEditor.Mode property is set to Filter, otherwise it defaults to the "rules" doc.

You can download default English versions of both documents (the filtering doc and the rules doc) used in Code Effects 4.x. Alternatively, you can get the same default documents by calling the RuleEditor.GetHelpXml() method (assuming that the RuleEditor.Mode is set to the proper value).

Use these documents as templates, translate all labels and messages in the template, and save it as a culture-specific file. When finished, tell Code Effects which Help XML file to use for the current user (for example, by extending our previous switch statement):

switch(currentCulture)
{
	case "de-DE":
		this.ruleControl.SourceXmlFile = Server.MapPath("/German/Source.config");
		this.ruleControl.HelpXmlFile = Server.MapPath("/German/Help.config");
		break;
	case "fr-FR":
		this.ruleControl.SourceXmlFile = Server.MapPath("/French/Source.config");
		this.ruleControl.HelpXmlFile = Server.MapPath("/French/Help.config");
		break;
}

As with Source XML, you can lower the amount of IO on the server by using the RuleEditor.HelpXml property of System.Xml.XmlDocument type instead of the HelpXmlFile. And you can also cache the help files on the server by setting the RuleEditor.CacheHelp property to True. Help caching is not provided in MVC version of Code Effects.

Post your support requests on Stackoverflow.com. You can also post your comments and product feedback using the form at the bottom of this page.
Comments: 0
Name (optional):
Comment (URLs are allowed and must start with http:// or https://; all tags will be encoded):
Remaining character count: