Module resilient.patches.lang
Hard-patch SILE language support to use BCP47 language tags.
CAVEAT EMPTOR: This is theoretically compatible with SILE up to (and including) 0.15.13. Future SILE versions may have a different implementation.
This minimal patch overrides the language support in SILE to accept and resolve BCP47 language tags,
such as en-GB
, es-MX
, fr-CH
, etc.
In other layman's terms, it changes the behavior of SILE's \language
command.
This implementation does not change how SILE's \font[language=...]
command works.
See SILE PR 1641 for details and more complete proposal.
We cannot wait forever for SILE to support BCP47 (and not just a 2-letter country code):
Markdown and Djot need to be able to support qualified language names, notably for smart quotes to work adequately.
Info:
- Copyright: (c) 2022, 2025 Omikhleia / Didier Willis
- License: MIT
Functions
SILE.languageSupport.loadLanguage (language) | (Hard-patch) Override SILE.languageSupport.loadLanguage() to accept BCP47 language tags and load resources accordingly. |
Local Functions
forLanguage (langbcp47, tableOrCallback) | Utility function to match a language against a table of entries or a callback function. |
Functions
- SILE.languageSupport.loadLanguage (language)
-
(Hard-patch) Override SILE.languageSupport.loadLanguage() to accept BCP47 language tags
and load resources accordingly.
Parameters:
- language string BCP47 language tag
Local Functions
- forLanguage (langbcp47, tableOrCallback)
-
Utility function to match a language against a table of entries or a callback function.
Find the "closest" matching language by looping and removing a language specifier,
until we get a non-nil match.
E.g. "xx-Xxxx-XX" will be matched against "xx-Xxxx--XX", "xx-Xxxx", "xx"
until one of these are satisfied.
Parameters:
- langbcp47 string Valid BCP47 canonical language
- tableOrCallback table or function Table of languages, or callback
Returns:
- any or nil Resource found, if any
- string or nil Matched language