Section 4.29 Localization
We briefly introduced PreTeXt support for authoring documents in multiple languages in Section 3.27. 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.26 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 37).
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.29.1 Localization Files
The prerequisite is that a localization file for your language exists. A number 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 1 .
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 2 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.3 in the Appendices for details.
Subsection 4.29.2 Changing the 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:
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.3 for details.