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 $(, $args:expr )* $(,)?) => {{
22        // Avoid holding references to temporaries by collecting owned Strings first.
23        // This prevents `E0716: temporary value dropped while borrowed` when
24        // callers pass temporary values like `path.display()` or format! results.
25        let mut __trf_store: Vec<String> = Vec::new();
26        $(
27            __trf_store.push(format!("{}", $args));
28        )*
29        // Build a vector of references to the owned strings. These references
30        // live for the duration of this block and are safe to pass to `tr_fmt`.
31        let __trf_refs: Vec<&dyn std::fmt::Display> =
32            __trf_store.iter().map(|s| s as &dyn std::fmt::Display).collect();
33        $crate::i18n::tr_fmt($key, &__trf_refs)
34    }};
35}
36
37pub mod assets;
38pub mod cli;
39pub mod cmds;
40pub mod errors;
41pub mod i18n;
42pub mod template;
43pub mod types;
44pub mod utils;
45pub mod utils_ext;