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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! Locale abstraction.
//!
//! Locales control:
//! - compact-number suffixes (`K` / `thousand` / inflected forms)
//! - decimal and grouping separators
//! - list formatting style (`and` word, serial comma, list separator)
//! - duration unit labels (`h` vs `hour`, pluralization)
//! - relative-time wording (`ago` word)
//! - ordinal suffixes (`st` / `.` / `-й`)
//!
//! The crate includes built-in locale packs (English by default, plus optional
//! Russian/Polish behind feature flags), and also provides [`crate::locale::CustomLocale`]
//! for ad hoc customization.
//!
//! You can also implement this trait for your own locale type. Keep in mind that
//! `Locale` requires `Copy + Clone + Default` to keep formatter options cheap.
//!
//! # Implementing a minimal locale
//!
//! ```rust
//! use humfmt::locale::{DurationUnit, Locale};
//!
//! #[derive(Copy, Clone, Debug, Default)]
//! struct Pirate;
//!
//! impl Locale for Pirate {
//! fn compact_suffix(&self, idx: usize, long: bool) -> &'static str {
//! let _ = long;
//! match idx {
//! 0 => "",
//! 1 => "k",
//! 2 => "m",
//! _ => "",
//! }
//! }
//!
//! fn and_word(&self) -> &'static str {
//! "arr"
//! }
//!
//! fn ago_word(&self) -> &'static str {
//! "back"
//! }
//!
//! fn ordinal_suffix(&self, _n: u128) -> &'static str {
//! "th"
//! }
//!
//! fn duration_unit(&self, unit: DurationUnit, count: u128, long: bool) -> &'static str {
//! let _ = count;
//! match (unit, long) {
//! (DurationUnit::Second, false) => "s",
//! (DurationUnit::Second, true) => "second",
//! _ => "?",
//! }
//! }
//! }
//! ```
/// Duration unit kind used by locale-aware duration and relative-time formatting.
///
/// Locales receive a `DurationUnit` plus a `count` and a `long` flag and are
/// expected to return an appropriate unit label.
///
/// This enum intentionally matches the unit set used by `humfmt`'s duration
/// formatter (days down to nanoseconds).
/// Locale customization trait.
///
/// This trait is intentionally small and uses `&'static str` outputs to keep
/// formatting allocation-free and `no_std` friendly.
///
/// Most users should use built-in locale packs or [`crate::locale::CustomLocale`]
/// rather than implementing `Locale` directly.