Choosing a translator

The toolkit has three translators, one for each flavour of EFX (see EFX Language Reference). This page helps you choose the ones that your application needs. It also shows which parts you write yourself, and which parts the toolkit already provides.

Translators by task

Task Translator Input

Display notices, for example as HTML or PDF

EfxTemplateTranslator

The template files of the SDK, in view-templates

Validate notices

EfxRulesTranslator

The rules files of the SDK, in validation

Evaluate single expressions, for example the conditions under which a field is mandatory or forbidden in a form

EfxExpressionTranslator

The expressions of the SDK, such as those in fields/fields.json

You can use several translators in the same application. EfxTemplateTranslator and EfxRulesTranslator both extend EfxExpressionTranslator, so each of them also translates single expressions.

Your application usually translates once, when it imports a new version of the SDK, and stores the result. It can also translate each time that it processes a notice, but this takes longer.

What each translator needs

Each translator needs a set of components, which it receives from a TranslatorDependencyFactory (see Assembling and running a translator):

Translator SymbolResolver ScriptGenerator MarkupGenerator ValidatorGenerator

EfxExpressionTranslator

✓

✓

EfxTemplateTranslator

✓

✓

✓

EfxRulesTranslator

✓

✓

✓

SymbolResolver

Gives the metadata of the fields, nodes and codelists of the SDK: their paths, types and repeatability (see Using the symbol resolver).

ScriptGenerator

Writes the expressions in your target language, such as XPath or JavaScript (see Implementing ScriptGenerator).

MarkupGenerator

Writes the output of template files in your target markup language, such as XSLT (see Implementing MarkupGenerator).

ValidatorGenerator

Writes the validation files of rules files, such as Schematron (see Implementing ValidatorGenerator).

The factory also gives the translator an ANTLR error listener, which decides what happens when the translator finds a syntax error.

Reusing the provided implementations

You can often reuse the implementations that already exist, and then you write only what is specific to your application:

Component Provided implementation Reuse it when

SymbolResolver

SdkSymbolResolver, in the toolkit

In most cases: it reads the metadata from the files of the SDK.

ScriptGenerator

XPathScriptGenerator, in the toolkit

Your target language uses XPath, as XSLT and Schematron do. For JavaScript, Python or another language, write your own.

MarkupGenerator

XslMarkupGenerator, in the Notice Viewer sample application

Only after you adapt it: the toolkit has no markup generator of its own. The generator of the Notice Viewer, which writes XSLT, is a good starting point.

ValidatorGenerator

SchematronGenerator, in the toolkit

You validate with Schematron.

So an application that validates notices with Schematron needs no component of its own: it reuses SdkSymbolResolver, XPathScriptGenerator and SchematronGenerator. An application that displays notices in HTML usually writes only a MarkupGenerator.


See also: