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
//! Gettext translations for Rust desktop apps.
//!
//! An app embeds its compiled catalogs in the binary and calls [`init_auto`] at startup. Code in
//! the app, and in any library the app depends on, then calls [`t`] and [`nt`] to get translated
//! strings.
//!
//! ```rust,no_run
//! use patois::{nt, t};
//!
//! patois::embed_domain!();
//!
//! fn main() {
//! patois::init_auto(env!("CARGO_PKG_NAME"));
//! println!("{}", t("Checking for updates..."));
//! println!("{}", nt("%d file", "%d files", 3).replacen("%d", "3", 1));
//! }
//! ```
//!
//! A library calls [`t`] and [`nt`] and needs no setup of its own: the strings resolve against the
//! catalog of the app that uses the library.
use Path;
pub use inventory;
pub use ;
pub use embed_domain;
pub use embed_wx_translations;
/// The catalogs that [`embed_domain!`] registers for one crate.
collect!;
/// Sets up translations for an app that loads its catalogs from disk.
///
/// Registers the locale directory of `domain`, makes `domain` the active domain, and activates
/// `locale_id`. The catalogs must be at `<locale_dir>/<locale>/LC_MESSAGES/<domain>.mo`.
///
/// [`LanguageManager`] and [`available_locales`] list embedded catalogs only, so they don't see
/// catalogs loaded this way.
///
/// # Panics
///
/// Panics if a thread panicked while it held the lock on the global translation state.
/// Sets up translations for an app that embeds its catalogs with [`embed_domain!`].
///
/// Makes `domain` the active domain and activates the catalog that best fits the system language,
/// as [`best_available_language`] chooses it. If no catalog fits, strings stay in English.
///
/// # Panics
///
/// Panics if a thread panicked while it held the lock on the global translation state.
/// Returns the translation of `s` in the active locale.
///
/// Returns `s` unchanged if no domain is active or the catalog has no translation.
///
/// # Panics
///
/// Panics if a thread panicked while it held the lock on the global translation state.
/// Returns the form of a plural string that fits `n` in the active locale.
///
/// The rule comes from the `Plural-Forms` header of the catalog. If no domain is active or the
/// catalog has no translation, returns `singular` when `n` is 1 and `plural` otherwise.
///
/// The result still contains its placeholder, so replace that with the number yourself.
///
/// # Panics
///
/// Panics if a thread panicked while it held the lock on the global translation state.
/// Changes the active locale.
///
/// Later calls to [`t`] and [`nt`] use the new locale. Case and the separator don't matter, so
/// `pt-BR`, `pt_br`, and `pt_BR` all select a catalog named `pt_br`. If there is no catalog for the
/// region, the catalog for the bare language is used.
///
/// # Panics
///
/// Panics if a thread panicked while it held the lock on the global translation state.
/// Returns the active locale in normalized form, such as `pt_BR`.
///
/// Returns an empty string before a locale is set.
///
/// # Panics
///
/// Panics if a thread panicked while it held the lock on the global translation state.
/// Makes `domain` the active domain without registering a locale directory.
///
/// Use this function when [`embed_domain!`] embeds the catalogs of `domain` and you choose the
/// locale yourself.
///
/// # Panics
///
/// Panics if a thread panicked while it held the lock on the global translation state.
/// Returns the locale codes of the catalogs embedded for `domain`.
///
/// The codes are the names of the directories under `locale/` at compile time, such as `de` and
/// `pt_br`.
/// Returns the preferred locale of the operating system in normalized form, such as `en_US`.
///
/// Returns `en` if the system locale can't be determined.