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
/**
Used for including json files into your executable binary file for building a `JSONGetText` instance.

```
#[macro_use] extern crate json_gettext;

let ctx = static_json_gettext_build!(
    "en_US",
    "en_US",
    "langs/en_US.json",
    "zh_TW",
    "langs/zh_TW.json"
)
.unwrap();

println!("{:?}", ctx);
```
**/
#[macro_export]
macro_rules! static_json_gettext_build {
    ( $default_key:expr, $($key:expr, $path:expr), * ) => {
        {
            use crate::json_gettext::JSONGetText;

            let mut builder = JSONGetText::build($default_key);

            $(
                builder.add_json($key, include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $path))).unwrap();
            )*

            builder.build()
        }
    };
}

/**
Used for getting single or multiple text from context.

```
#[macro_use] extern crate json_gettext;

let ctx = static_json_gettext_build!(
    "en_US",
    "en_US",
    "langs/en_US.json",
    "zh_TW",
    "langs/zh_TW.json"
)
.unwrap();

assert_eq!("Hello, world!", get_text!(ctx, "hello").unwrap());
assert_eq!("哈囉,世界!", get_text!(ctx, "zh_TW", "hello").unwrap());
```
*/
#[macro_export]
macro_rules! get_text {
    ( $ctx:ident, $text:expr ) => {
        {
            $ctx.get_text($text)
        }
    };
    ( $ctx:ident, $key:expr, $text:expr ) => {
        {
            $ctx.get_text_with_key($key, $text)
        }
    };
    ( $ctx:ident, $key:expr, $text:expr, $($text_array:expr), + ) => {
        {
            let mut text_array = vec![$text];

            $(
                {
                    text_array.push($text_array);
                }
            )*

            $ctx.get_multiple_text_with_key($key, &text_array)
        }
    };
}

/// Used for including json files into your executable binary file for building a `JSONGetTextManager` instance. In order to reduce the compilation time and allow to hot-reload json data, files are compiled into your executable binary file together, only when you are using the **release** profile.
#[cfg(all(debug_assertions, feature = "rocketly"))]
#[macro_export]
macro_rules! static_json_gettext_build_rocketly {
    ( $default_key:expr, $($key:expr, $path:expr), * ) => {
        {
            let mut v = Vec::new();

            $(
                v.push(($key, $path));
            )*

            ($default_key ,v)
        }
    };
}

/// Used for including json files into your executable binary file for building a `JSONGetTextManager` instance. In order to reduce the compilation time and allow to hot-reload json data, files are compiled into your executable binary file together, only when you are using the **release** profile.
#[cfg(all(not(debug_assertions), feature = "rocketly"))]
#[macro_export]
macro_rules! static_json_gettext_build_rocketly {
    ( $default_key:expr, $($key:expr, $path:expr), * ) => {
        {
            let mut v = Vec::new();

            $(
                v.push(($key, include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $path))));
            )*

            ($default_key ,v)
        }
    };
}