Localization - iamgio/quarkdown GitHub Wiki
Quarkdown supports string localization out of the box.
The first step is to set the document language via .doclang {locale}
and it's suggested to call it among the other document metadata (such as .docname
, .docauthor
, etc.).
locale
can be represented as either a case-insensitive English full name (e.g. English
, Italian
, French (Canada)
) or a IETF BCP 47 language tag (e.g. en
, it
, fr-CA
).
Built-in localization
The stdlib exposes a look-up localization table that allows localizing many built-in aspects of Quarkdown, such as quote types, numbering captions, and table of contents title.
The currently supported locales are English and Italian, with more coming soon (contributions are welcome).
Creating your own localized strings
This feature might be widely useful to library makers.
Imagine a function .theorem
that displays the paragraph name Theorem.
, LaTeX style:
.function {theorem}
**Theorem.**
.theorem This is my theorem...
Output:
Theorem. This is my theorem...
This is great if you're making it for your own English document, but what if you're making a library for everyone to use? You'd need to support multiple languages.
Localization table
The .localization {name}
function defines a new localization table associated with a unique name.
Its body parameter accepts a particular Markdown unordered list that, in Quarkdown, is called a dictionary.
This localization dictionary exposes key-value pairs for each locale that you intend to support.
The locale names follow the same rules as the ones from .doclang
, hence they can be full names or tags.
.localization name:{mylib}
- English
- theorem: Theorem
- Italian
- theorem: Teorema
Localizing
As long as .doclang
is set, the localized string can be accessed via .localize {table:key}
, in this case .localize {mylib:theorem}
.
The previous function would now look like this:
.function {theorem}
**.localize {mylib:theorem}.**
.theorem This is my theorem...