json-gettext 3.1.4

A library for getting text from JSON usually for internationalization.
Documentation
/// 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)
        }
    };
}