Menu
Public repository / f1f33c69567a554b6ce011822661d3289c1e9c77
AkurAI-Framework / crates/i18n/src/lib.rs
Latest change 9876ca1b84b75a78bec25332729ec70f36d4df3d - feat(i18n): add akurai-i18n crate and {{ t }} template helper by Ólafur Búi Ólafsson
//! AkurAI-Framework internationalisation — pure `std` (+ internal `akurai-json`).
//!
//! Loads per-locale JSON message catalogs from a directory and provides
//! key lookup with automatic fallback.
//!
//! # Catalog format
//!
//! One JSON file per locale, named by locale code:
//!
//! ```text
//! locales/
//! en.json → { "hello": "Hello", "greeting": "Hello, {name}!" }
//! is.json → { "hello": "Halló", "greeting": "Halló, {name}!" }
//! ```
//!
//! # Loading
//!
//! ```no_run
//! use akurai_i18n::Catalogs;
//! use std::path::Path;
//!
//! let catalogs = Catalogs::load_dir(Path::new("locales")).unwrap();
//! assert_eq!(catalogs.translate("is", "hello"), "Halló");
//! ```
//!
//! # Template integration
//!
//! The AkurAI template engine reads the reserved context keys `__locale`
//! (the active locale code, a `Str`) and `__messages` (an `Object` mapping
//! message keys to their translated strings). The CLI is responsible for
//! injecting those into the render context; the template crate is decoupled
//! from this crate and does only cheap map lookups.
//!
//! See `site/content/docs/i18n.md` for the full wiring guide.
#![forbid(unsafe_code)]
mod catalog;
mod error;
pub use catalog::Catalogs;
pub use error::Error;