Placeholder tags

An example for working with placeholder tags—in this case, Mustache tags.

Mustache is a template system that provides “logic-less templates”. From the Mustache manual:

Mustache can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.

Using the DeepL API to translate text that includes Mustache tags can present a challenge. In most if not all cases, users would not want to translate the tag key inside a Mustache tag, as the tag key is used to reference values in a hash or object. However, the DeepL API does not recognize Mustache tags and does not have a built-in parameter that can be used to exclude them from translation.

It is possible, however, to pre- and post-process text containing Mustache tags in order to preserve the Mustache tag key during translation. In the Python client library, we include an example showing how this can be done.

A similar approach could be used for other types of placeholder tags that are not recognized by the DeepL API when users do not want to translate the content inside the tags.

Below is a summary of the Mustache example, and for more detail, you can refer to the example's README.

  • The input Mustache template is parsed to separate the literal text from the Mustache tags.

  • The template is modified to replace all Mustache tags with placeholder XML tags. Unique IDs are attached to each placeholder tag to identify them in the translated XML.

  • The XML template is translated using DeepL API with XML tag handling activated.

  • The translated XML is parsed to identify placeholder tags and replace them with the original Mustache tags.

Please note when using Mustache or other placeholder tags, the translation engine would not know the context or meaning of a tag (i.e. the engine would not know if a tag will populate a name, or an address, or a color, or a numerical value, etc). This lack of context might affect the quality of the translation output.

Last updated