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
use crate::;
pub use ;
use ;
use LangID;
use ;
/// An enum representing types of Fluent loaders
/// - Static loader (which loads Fluent resources(i18n/l10n resources) at compile time)
/// - Ref Arc loader (which can load resources at runtime).
/// - In addition to `&'a ArcLoader`, you can also use `&'static ArcLoader`.
/// - Owned Arc loader (The main difference with the `Ref Arc loader` is that it has ownership).
///
/// | Variable | Type | Description |
/// | ---------- | ----------------------- | ----------------------------------------------------------------------------------------------- |
/// | `Static` | `&'static StaticLoader` | Allows loading Fluent resources at compile time. |
/// | `Arc` | `&'a ArcLoader` | Allows loading resources at runtime. Both `&'static ArcLoader` and `&'a ArcLoader` can be used. |
/// | `ArcOwned` | `ArcLoader` | The main difference from `&'a ArcLoader` is that it has ownership. |
/// Creates a new `ArcLoader` instance by configuring an `ArcLoaderBuilder`.
///
/// # Parameters
///
/// - `dir`: A reference to the directory path containing the translation files.
/// - `shared`: Some fluent resources that are shared with all locales. For example, if **core.ftl** has `-app-name = glossa`, then if `shared` contains the file **core.ftl**, then **-app-name** will be shared.
///
/// # Returns
///
/// Returns a `Result` containing the newly created `ArcLoader`,
/// or a `GlossaError` if there was a problem creating the loader.
///
/// # Examples
///
/// ```no_run
/// use glossa::fluent::{
/// loader::{new_arc_loader, ArcLoader},
/// LangResource,
/// };
/// use once_cell::sync::Lazy;
/// use std::path::PathBuf;
///
/// static LOADER: Lazy<ArcLoader> = Lazy::new(|| {
/// // "assets/test/i18n" is a resource dir.
/// // "assets/test/i18n/en/main.ftl", "assets/test/i18n/en-GB/main.ftl" are some fluent resources.
/// new_arc_loader(&PathBuf::from_iter(["assets", "test", "i18n"]), None)
/// .expect("Failed to create arc loader")
/// });
/// let res = LangResource::from_arc_loader(&LOADER);
/// ```
// #[cfg(test)]
// mod tests {
// use crate::l10n::locales;
// #[test]
// fn get_log_resource_loader() {
// const LOG_KEY: &str = "FluentLoader-get_locales";
// dbg!("{}", locales().get_or_default(LOG_KEY));
// }
// }