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
/// Errors for translators. These are separate so new translators can easily be
/// created in a modular fashion.
pub mod errors;

// We export each translator by name
#[cfg(feature = "translator-fluent")]
mod fluent;
#[cfg(feature = "translator-fluent")]
pub use fluent::{FluentTranslator, FLUENT_TRANSLATOR_FILE_EXT};

#[cfg(feature = "translator-lightweight")]
mod lightweight;
#[cfg(feature = "translator-lightweight")]
pub use lightweight::{LightweightTranslator, LIGHTWEIGHT_TRANSLATOR_FILE_EXT};

#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
mod dummy;
#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
pub use dummy::{DummyTranslator, DUMMY_TRANSLATOR_FILE_EXT};

// And then we export defaults using feature gates
#[cfg(feature = "translator-fluent")]
pub use FluentTranslator as Translator;
#[cfg(feature = "translator-fluent")]
pub use FLUENT_TRANSLATOR_FILE_EXT as TRANSLATOR_FILE_EXT;

#[cfg(feature = "translator-lightweight")]
pub use LightweightTranslator as Translator;
#[cfg(feature = "translator-lightweight")]
pub use LIGHTWEIGHT_TRANSLATOR_FILE_EXT as TRANSLATOR_FILE_EXT;

// And then we export the appropriate macro backends, hidden from the docs
#[cfg(feature = "translator-fluent")]
#[doc(hidden)]
pub use fluent::link_macro_backend;
#[cfg(feature = "translator-fluent")]
#[doc(hidden)]
pub use fluent::t_macro_backend;
#[cfg(feature = "translator-fluent")]
#[doc(hidden)]
pub use fluent::t_macro_backend_with_args;
#[cfg(feature = "translator-fluent")]
pub use fluent::TranslationArgs;

#[cfg(feature = "translator-lightweight")]
#[doc(hidden)]
pub use lightweight::link_macro_backend;
#[cfg(feature = "translator-lightweight")]
#[doc(hidden)]
pub use lightweight::t_macro_backend;
#[cfg(feature = "translator-lightweight")]
#[doc(hidden)]
pub use lightweight::t_macro_backend_with_args;
#[cfg(feature = "translator-lightweight")]
pub use lightweight::TranslationArgs;

#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
#[doc(hidden)]
pub use dummy::link_macro_backend;
#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
#[doc(hidden)]
pub use dummy::t_macro_backend;
#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
#[doc(hidden)]
pub use dummy::t_macro_backend_with_args;
#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
pub use dummy::TranslationArgs;

// If no translators have been specified, we'll use a dummy one
#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
pub use DummyTranslator as Translator;
#[cfg(all(
    not(feature = "translator-fluent"),
    not(feature = "translator-lightweight")
))]
pub use DUMMY_TRANSLATOR_FILE_EXT as TRANSLATOR_FILE_EXT;

/// Translates the given ID conveniently, taking arguments for interpolation as
/// required. The final argument to any call of this macro must be a Sycamore
/// reactive scope provided to the relevant Perseus template.
#[macro_export]
macro_rules! t {
    // When there are no arguments to interpolate
    ($cx:expr, $id:expr) => {
        $crate::i18n::t_macro_backend($id, $cx)
    };
    // When there are arguments to interpolate
    ($cx:expr, $id:expr, {
        // NOTE Using a colon here leads to literally impossible to solve cast errors based on compiler misinterpretations
        $($key:literal = $value:expr),+
    }) => {{
        let mut args = $crate::i18n::TranslationArgs::new();
        $(
            args.set($key, $value);
        )+
        $crate::i18n::t_macro_backend_with_args($id, args, $cx)
    }};
}
/// Gets the link to the given resource in internationalized form conveniently.
/// The final argument to any call of this macro must be a Sycamore reactive
/// scope provided to the relevant Perseus template.
#[macro_export]
macro_rules! link {
    ($cx:expr, $url:expr) => {
        $crate::i18n::link_macro_backend($url, $cx)
    };
}