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
//! Macro declarations for the `translatable` crate.
//!
//! This crate shouldn't be used by itself,
//! since the macros generate code with the context
//! of the `translatable` library.
//!
//! The `translatable` library re-exports the macros
//! declared in this crate.
use TokenStream;
use parse_macro_input;
use crate translation_macro;
use crate TranslationMacroArgs;
/// **translation obtention macro.**
///
/// This macro generates the way to obtain a translation
/// from the translation files in the directory defined
/// in the `translatable.toml` file.
///
/// **Parameters**
/// * `language` - A string literal for static inference or an instance of
/// `translatable::Language` for dynamic inference.
/// * `path` - A pat prefixed with `static` for static inference or a `Vec<impl
/// ToString>`
/// for dynamic inference.
/// * `replacements` - Arguments similar to python's `kwargs` for the
/// translation replacements.
///
/// This macro provides optimizations depending on the dynamism
/// of the parameters while calling the macro.
///
/// The optimizations are described the following way
/// - If path is static, no runtime lookup will be required
/// - If the path is dynamic, the file structure will be hardcoded.
///
/// - If the language is static, the validation will be reported by
/// `rust-analyzer`.
/// - If the language is dynamic the validation will be reported in runtime in
/// the `Err` branch.
///
/// - If both are dynamic a single [`String`] will be generated.
///
/// Independently of any other parameter, the `replacements` parameter
/// is always dynamic (context based).
///
/// You can shorten it's invocation if a similar identifier is on scope,
/// for example `x = x` can be shortened with `x`.
///
/// Replacement parameters are not validated, if a parameter exists it will be
/// replaced otherwise it won't.
///
/// **Returns**
/// A `Result` containing either:
/// * `Ok(String)` - If the invocation is successful.
/// * `Err(translatable::Error)` - If the invocation fails with a runtime error.