Skip to main content

The PreTeXt Guide

Section 4.38 Localization

We briefly introduced PreTeXt support for authoring documents in multiple languages in Section 3.29. Here are some more details.
First, authors are encouraged to write the actual text of their documents using the language of their choice. See Section 4.34 for details. For HTML this should be straightforward, for other output formats (especially PDF) the publisher may need to have various fonts installed (see Chapter 40).
Localization for PreTeXt itself is restricted to the items PreTeXt names for you. This includes things like <theorem>, but also items such as the labels of navigation buttons. To have this in your language requires two things, described in the following subsections.

Subsection 4.38.1 Localization Files

The prerequisite is that a localization file for your language exists. Fifteen languages are already supported, such as es-ES (Peninsular Spanish), pt-BR (Brazilian Portuguese), and hu-HU (Hungarian/Magyar); the default language code is en-US (American English). For a up-to-date list of which languages are available, see the localization stylesheet folder on GitHub
If such a file does not exist, you will need to create one or find someone to help you do so. Brief instructions for this are in the README file
for this directory. These instructions suggest using the en-US file as a template and as a source of more detailed instructions. We highly encourage anyone who creates such a file to contribute it to our growing list of localization stylesheets; see Section A.4 in the Appendices for details.

Subsection 4.38.2 Changing the Document Language

In order to use a localization, simply place xml:lang="es-ES" (with language code as appropriate for your project) as an attribute on your <pretext> element. For example:
<pretext xml:lang="hu-HU"/>
Then you can process your source as usual. Be sure to check that the translations look appropriate in your output.
While processing your source, you may encounter warnings for missing translations, like this:
MBX:WARNING: could not translate string with id
"hypothesis" into language for code "pt-PT"
In this case, the localization stylesheet is missing a translation for this tag, and it will remain in en-US. We welcome contributions to keep stylesheets fully complete; see Section A.4 for details.

Subsection 4.38.3 Multilingual Documents

As of the start of 2023, we are improving support to allow for parts of a document to be in different languages. Much as you place an @xml:lang attribute on the overall <pretext> element, you can place this attribute, with a different supported language onto any element, and all of the content within that element should react according to the new language. A division would be most natural, but perhaps also a block or a paragraph? Development continues, and in particular not every part of an HTML page always reacts.