1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! A lightweight, high-performance localization library.
//!
//! `lang-lib` loads TOML language files, supports runtime locale switching,
//! configurable file paths, and automatic fallback chains. It is designed to
//! be dropped into any project without ceremony.
//!
//! # What This Crate Does Well
//!
//! - Keeps the runtime model simple: load files once, then translate by key.
//! - Uses plain TOML so translators and developers can inspect files easily.
//! - Works across platforms by resolving file paths with native path handling.
//! - Fails predictably with typed errors when files are missing or invalid.
//!
//! # Quick Start
//!
//! ```rust,no_run
//! use lang_lib::{t, Lang};
//!
//! // Configure once at startup
//! Lang::set_path("locales");
//! Lang::load("en").unwrap();
//! Lang::load("es").unwrap();
//! Lang::set_locale("en");
//!
//! // Translate anywhere
//! let msg = t!("bad_password");
//! let msg_es = t!("bad_password", "es");
//! let msg_fb = t!("missing_key", fallback: "Default message");
//! ```
//! # Small Tutorial
//!
//! 1. Create a directory for locale files.
//! 2. Add one TOML file per locale.
//! 3. Load the locales your application needs at startup.
//! 4. Set the active locale for the current process.
//! 5. Use [`t!`] anywhere you need translated text.
//!
//! Example layout:
//!
//! ```text
//! your-app/
//! |- Cargo.toml
//! |- src/
//! | \- main.rs
//! \- locales/
//! |- en.toml
//! \- es.toml
//! ```
//!
//!
//! # File Format
//!
//! Language files are plain TOML, one key per line:
//!
//! ```toml
//! bad_password = "Your password is incorrect."
//! welcome_user = "Welcome back"
//! not_found = "The page you requested does not exist."
//! ```
//!
//! Files are resolved as `{path}/{locale}.toml`.
//!
//! # Behavior Notes
//!
//! Lookup order is deterministic:
//!
//! 1. Requested locale, or the active locale when none is provided
//! 2. Each configured fallback locale in order
//! 3. The inline fallback passed to [`t!`]
//! 4. The key itself
//!
//! Non-string TOML values are ignored on purpose. That keeps translation data
//! flat and avoids surprising coercions at runtime.
//!
//! # Examples
//!
//! See the runnable example in `examples/basic.rs` for a complete setup using
//! real locale files.
//! See `examples/server.rs` for a server-oriented pattern that resolves a
//! locale per request and passes it explicitly during translation.
//! See `examples/axum_server.rs` for the same pattern inside a real HTTP
//! handler using `axum`.
//! See `examples/actix_server.rs` for the same pattern using `actix-web`.
//! Locale names must be a single file stem such as `en`, `en-US`, or `pt_BR`.
pub use LangError;
pub use ;
pub use ;
/// Translates a key using the active locale.
///
/// Falls back through the fallback chain and finally returns the key itself
/// if no translation is found anywhere.
///
/// # Examples
///
/// ```rust,no_run
/// use lang_lib::t;
///
/// // Active locale
/// let msg = t!("greeting");
///
/// // Specific locale
/// let msg = t!("greeting", "es");
///
/// // Inline fallback
/// let msg = t!("unknown_key", fallback: "Hello");
/// ```