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)
ItemReported when
MissingPagea page has a file in other locales but not in this one
MissingKeya key of the default locale is missing in this locale
Placeholdersthe {names} of a key differ from the default locale's
PluralFormsa message with | has a number of forms the locale's plural rules don't expect
PluralShapethe zero form has a {, or a shared form lacks {count}, so tc reads the forms by index
BrokenLinka linked message was left as written, with the reason
  • The default locale is defaultLocale of i18n.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 let check() 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"
EventLevelFields
i18n-next: missing translationwarnlocale, page (index for the root), key
i18n-next: missing format, default options usedwarnkind (number / datetime), name, locale
i18n-next: load failedwarnerror: a lazy file that cannot be read
i18n-next: loaddebugpath, bytes, micros: a file read
i18n-next: add_filedebugpath, bytes, micros: a remote file added
i18n-next: reloaddebugmicros: one reload
span i18n_next::ensuredebugpath: 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.