Guides
Checks and tracing
check() for the catalog, typed keys, the CLI and tracing events.
check()
#[test]
fn translations_are_complete() {
let i18n = i18n_next::I18n::builder()
.config("i18n.json")
.dir("locales")
.linked_messages(true)
.build()
.unwrap();
let report = i18n.check();
assert!(report.is_clean(), "{report}");
}
check() returns a CheckReport: items (one CheckItem per problem), is_clean(), and a Display with one
line per item:
catalog check: 4 problem(s)
- de: no file for page "about" (other locales have one)
- de/index: "bye" is missing (the default locale has it)
- de/index: "hi" has {nam}, the default locale {name}
- en/index: "cars" has 2 plural forms, expected 3 (zero | one | other)
| Item | Reported when |
|---|---|
MissingPage | a page has a file in other locales but not in this one |
MissingKey | a key of the default locale is missing in this locale |
Placeholders | the {names} of a key differ from the default locale's |
PluralForms | a message with | has a number of forms the locale's plural rules don't expect |
PluralShape | the zero form has a {, or a shared form lacks {count}, so tc reads the forms by index |
BrokenLink | a linked message was left as written, with the reason |
- The default locale is
defaultLocaleofi18n.json, else the start locale. - Lazy files are read for the check. Disabled locales are skipped.
- Every string with a
|is a plural: a title like"Home | Acme"is reported.
Typed keys and CLI
- Frontend:
@i18n-micro/types-generator, see Tauri. - Rust: no key generator yet. Keep keys as
key!constants in one module and letcheck()catch what the files lack. @i18n-micro/cli(check,lint,translate, export / import) works on the same files.
Tracing
Cargo.toml
i18n-next = { version = "0.1", features = ["tracing"] }
tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init();
let i18n = I18n::builder().dir("locales").build()?; // "i18n-next: load" per file
i18n.t("nope"); // WARN i18n-next: missing translation locale="en" page="index" key="nope"
| Event | Level | Fields |
|---|---|---|
i18n-next: missing translation | warn | locale, page (index for the root), key |
i18n-next: missing format, default options used | warn | kind (number / datetime), name, locale |
i18n-next: load failed | warn | error: a lazy file that cannot be read |
i18n-next: load | debug | path, bytes, micros: a file read |
i18n-next: add_file | debug | path, bytes, micros: a remote file added |
i18n-next: reload | debug | micros: one reload |
span i18n_next::ensure | debug | path: one fetch of ensure_async |
The builder's missing handler is still called. Without the feature, debug builds write a lazy file that cannot be
read and an unknown named format to stderr. In a Tauri app the dev report is often handier for misses: see
Tauri.