Localization
Renzora has one process-wide translation table, read by every crate, the editor image and every native plugin through one function:
renzora::lang::t("menu.file") // "File", "Fichier", ...
The table lives in the contract layer renzora_lang_api, embedded once in the shared renzora_dylib image, so there is exactly one copy across the plugin boundary. The renzora_lang runtime plugin fills it and keeps the active language in sync.
That single copy is load-bearing. A plugin that somehow linked a private copy of the contract would get its own empty table, and every string it drew would render as its raw key (menu.file) with nothing logged, because a missing translation is not an error. Raw keys across a plugin's UI mean a shared image is missing, not a missing translation.
How a string resolves
t(key) never fails. It returns, in order:
- the active language's text, if it has the key;
- English (
en), the complete fallback; - the key itself.
So converting a literal to t("...") is always safe: an untranslated key shows English, and a key with no entry shows the key.
| Function | |
|---|---|
t(key) | the rules above |
t_or(key, fallback) | your fallback instead of the key, for plugins that ship no English pack |
t_in(code, key) | a specific language, regardless of the active one |
t_args(key, &[("name", value)]) | replaces {name} placeholders |
// "Saved {file}" becomes "Saved player.bsn"
renzora::lang::t_args("status.saved", &[("file", &name)]);
Where languages come from
- Built-in packs, compiled into the binary from the repository's
languages/folder, so an exported game is localized with no extra files. The engine ships 30, each complete against English. - External packs:
languages/*.tomlbeside the executable or in the working directory. They load on top and override a built-in pack of the samecode, key for key. The editor watches those folders, so saving a pack updates the running editor. - Project packs: the project's own
languages/*.tomlhold the game's strings in the same format. They merge over the built-ins (a project'sfr.tomlneeds only the game's keys), and may add a language the engine does not ship. The editor loads them when the project opens and re-reads one when it is saved; an export packs every one into the game. - Plugin contributions, below.
Pack format
A pack is TOML: a [meta] header and a flat [strings] table.
[meta]
name = "Français" # native name shown in pickers
code = "fr" # "fr", "pt-BR", "zh", "zh-TW"
author = "Renzora Team"
version = "1.0"
[strings]
"common.ok" = "OK"
"menu.file" = "Fichier"
Keys are dotted and grouped by area (common.*, menu.*, one group per panel). English (languages/en.toml) is the source of truth for which keys exist. parse_pack(text) parses one without registering it, for tooling.
Adding translations from a plugin
Registration is on the contract layer, so a plugin needs no dependency on renzora_lang:
impl Plugin for MyPlugin {
fn build(&self, app: &mut App) {
// a whole pack, embedded in the plugin
if let Err(e) = renzora::lang::register_pack_str(include_str!("../languages/de.toml")) {
warn!("my_plugin: German pack: {e}");
}
// or a handful of keys inline
renzora::lang::register_translations("en", [
("my_plugin.title", "My Plugin"),
("my_plugin.run", "Run"),
]);
}
}
Order does not matter: the table accumulates every contribution and t() resolves at call time. A later write to the same language and key wins, so a user's external pack can override a plugin's strings. Prefix keys with the plugin's name so they cannot collide.
Switching language
renzora::lang::set_active("ja");
renzora::lang::active_code(); // "ja"
renzora::lang::has_language("ja"); // true once a pack for it is registered
renzora::lang::available(); // every registered language, for a picker
Setting a code with no pack yet is allowed: install the pack later and it takes effect without another call.
The language a session starts in
The editor and a game choose differently, because the editor's language is the person editing's preference and a game's is the game's:
- The editor starts in the interface language saved in
~/.renzora/settings.toml([app] language), which the editor's language pickers write. - A game starts in the project's
default_language(a top-level key inproject.toml, such as"de"or"pt-BR"). Without one it follows the player's system language when a pack for it exists (de-DEfindsde,zh-Hant-TWfindszh-TW), and otherwise English. A game never reads the editor's settings, so a game exported from a German editor does not start in German unless the project says so.
# project.toml, above the first [section]
default_language = "fr"
RENZORA_LANG in the environment overrides both, which is useful for testing a translation or taking screenshots. The language can still change at run time with set_active.
Reacting to a change
When the active language changes or packs reload, renzora_lang sends a LanguageChanged message, and revision() returns a counter that moves on every change:
fn relocalize(mut changed: MessageReader<renzora::lang::LanguageChanged>) {
for _ in changed.read() {
// rebuild cached text
}
}
Game UI markup written as {{ t("key") }} follows the change on the next frame.
Scripts
Every scripting backend gets a tr(key) function, declared by renzora_lang's script extension. A Rust script has &mut World and simply calls renzora::lang::t. See Script Extensions.