kam/
lib.rs

1// kam library
2//
3// Export a small formatting translation macro at crate root so it can be used
4// from any module without needing to import it. The macro delegates to the
5// `i18n` module's translation templates and then formats the result, which
6// keeps translation responsibilities centralized.
7//
8// NOTE:
9// - We define this macro here (crate root) to ensure it's always visible even
10//   when other modules are compiled before the i18n module's implementation.
11// - This macro intentionally mirrors the behaviour in the `i18n` module:
12//   it gets the localized template via `crate::i18n::tr_key(...)` and then
13//   applies `format!` with the provided arguments.
14// - If you also keep a macro with the same name inside `i18n.rs`, you may
15//   want to remove or avoid duplication there. The crate root version is a
16//   guaranteed, early-available definition.
17// kam library
18
19#[macro_export]
20macro_rules! trf {
21    ($key:expr) => {
22        crate::i18n::tr_key($key).to_string()
23    };
24    ($key:expr, $($args:expr),+ $(,)?) => {
25        {
26            // Build a slice of &dyn Display that can be passed to the runtime formatter.
27            // We can't call `format!(template, ..)` because `format!` requires a
28            // compile-time string literal for the format, so we delegate to a
29            // runtime function `crate::i18n::tr_fmt` which handles formatting.
30            let args_slice: &[&dyn std::fmt::Display] = &[
31                $( &($args) as &dyn std::fmt::Display ),+
32            ];
33            crate::i18n::tr_fmt($key, args_slice)
34        }
35    };
36}
37
38pub mod assets;
39pub mod cli;
40pub mod cmds;
41pub mod errors;
42pub mod i18n;
43pub mod template;
44pub mod types;
45pub mod utils;
46pub mod utils_ext;