Localization
Defining phrases
Localization of modules are built around what we call phrases. Each phrase has a globally unique lisp-case
name and are built from merging all lang.toml
files in the repositories subscribed to by the user.
The lang.toml
consists of tables of phrases containing key-value pairs of ISO 639‑1 language codes and the respective translations in that locale, you can see an example below.
[good-morning]
en = "Good morning"
de = "Guten Morgen"
zh = "早上好"
[good-night]
en = "Good night"
de = "Gute Nacht"
zh = "晚安"
If the user's language is not present for a phrase after merging of all the tables, we first look for an English translation and if not present the first defined language for the phrase.
Machine translation
All lang.toml
files will be automatically translated using our machine-learning backend unless opted out. In order to give the system more context, we allow a special entry called context
. The context
should be given an example sentence in English or the first defined language where the word is replaced by {}
. You can also set it to !
to disable machine translation.
To demonstrate the use case of this parameter, consider the French word Bleu
which can mean bruise
, blue
, rookie
and overall
.
- Without context
- With context
[bruise]
fr = "bleu"
# Machine generated:
en = "Blue"
de = "Blau"
es = "Azul"
ko = "푸른"
ja = "青い"
zh-cn = "蓝色的"
zh-tw = "藍色的"
ru = "Синий"
pl = "Niebieski"
pt = "Azul"
tr = "Mavi"
da = "Blå"
nl = "Blauw"
fi = "Sininen"
sv = "Blå"
no = "Blå"
el = "Μπλε"
hu = "Kék"
it = "Blu"
cs = "Modrý"
ro = "Albastru"
[bruise]
context = "J'ai un {} à la jambe." # 'I have a bruise on my leg.'
fr = "bleu"
# Machine generated:
en = "Bruise"
de = "Blauen Fleck"
es = "Moretón"
ko = "멍"
ja = "あざ"
zh-cn = "瘀伤"
zh-tw = "瘀傷"
ru = "Синяк"
pl = "Siniaka"
pt = "Contusão"
tr = "Çürük"
da = "Blå Mærke"
nl = "Kneuzing"
fi = "Mustelma"
sv = "Blåmärke"
no = "Blåmerke"
el = "Μώλωπα"
hu = "Zúzódás"
it = "Livido"
cs = "Modřinu"
ro = "Vânătaie"
Zero-overhead replacement
Localization is a builtin part of our text renderer which allows you to localize phrases with practically zero overhead. Any user-facing text rendered by the following funtions will be automatically checked for any phrases present:
Engine.Info
Engine.Warn
Engine.Error
Engine.DisplayMessage
Text.Calc
, unless disabled usingText.NOLOCAL
CommandBuffer.Text2D
, unless disabled usingText.NOLOCAL
CommandBuffer.Text3D
, unless disabled usingText.NOLOCAL
Phrases are escaped using two curly brackets around the phrase name ({{phrase-name}}
) and any phrase with no entry in the table will be ignored.
Here's an example using our previous lang.toml
example.
Event.OnRender((gfx) => {
gfx.text2D(vec2(300, 100), 0, "{{good-morning}} {{invalid}}!", 32);
});

Manual translation
Phrases can also be manually translated using the function Phrase.Translate
which replaces all escaped phrases similar to the rendering primitives, or using the table Phrase.Table
using the phrase name as the key.
-- Global table with all known phrases.
--
table Phrase.Table
-- Translates each known phrase in the text according to user locale.
--
string Phrase.Translate(string input)