Navigation

Categories
Show Navigation Next Topic  »

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:

multilingual-source

When all Source XML docs are finished and saved, you need to tell Rule Editor 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.ruleEditorInstance.SourceXmlFile = Server.MapPath("/German/Source.config");
		break;
	case "fr-FR":
		this.ruleEditorInstance.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.

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. Rule Editor 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. Rule Editor 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.

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.ruleEditorInstance.SourceXmlFile = Server.MapPath("/German/Source.config");
		this.ruleEditorInstance.HelpXmlFile = Server.MapPath("/German/Help.config");
		break;
	case "fr-FR":
		this.ruleEditorInstance.SourceXmlFile = Server.MapPath("/French/Source.config");
		this.ruleEditorInstance.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.


Post your questions on Stackoverflow and become a part of our growing community

Comments: 0