Skip to main content

Crate ravenrs_app_i18n

Crate ravenrs_app_i18n 

Source
Expand description

The languages and the words of a RavenRS business application, in one place.

Every text the framework shows has a key, as ui.save or report.show. The texts that come with it are in English and in Brazilian Portuguese; a language without a key falls back to English, and a key nobody has shows as itself. An application or a module adds or replaces texts with a flat JSON of keys, without code of its own for the screens.

use ravenrs_app_i18n::{Catalog, Language, Texts};

let texts = Texts::new(Language::BrazilianPortuguese);
assert_eq!(texts.get("ui.save"), "Salvar");
assert_eq!(texts.format("rules.required", &["Nome"]), "Nome é obrigatório");

let mut catalog = Catalog::builtin();
catalog.merge_json("pt-BR", r#"{ "ui.save": "Gravar", "shop.checkout": "Fechar pedido" }"#)?;
let texts = catalog.texts(Language::BrazilianPortuguese);
assert_eq!(texts.get("ui.save"), "Gravar");
assert_eq!(texts.get("shop.checkout"), "Fechar pedido");

Modules§

model
Translations of the model that come with the framework, as differences in JSON for translation: the captions of the entities and navigation its modules add.

Structs§

Catalog
Texts by language and by key.
TextError
What is wrong with texts given as JSON.
Texts
The texts of a catalog in one language.

Enums§

Language
A language the screens can be in.

Constants§

FALLBACK
The language everything falls back to.

Functions§

format
A template with {0}, {1}… replaced by these. A number with nothing for it stays as it was.
format_with
A template with each {0}, {1}… written by value, straight into what it gives, so nothing else is made for each value. value says false for a number it has nothing for, which then stays as it was.