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
pub mod constants;
pub use constants::{STD_PATH};
pub mod structs;
pub use structs::{localizer::Localizer};
#[cfg(feature = "format")]
pub(crate) use structs::{Member};
mod funcs;
pub use funcs::{finds, finds_all};
mod traits;
pub use traits::*;
#[cfg(not(feature = "no_std"))]
use std::collections::HashMap;
#[cfg(not(feature = "no_std"))]
pub use std::fmt::Display;
#[cfg(feature = "no_std")]
pub use core::fmt::Display;
#[cfg(not(feature = "no_std"))]
use enums::standart::res_keeper;
pub mod enums;
pub use enums::serialize_form;
use std::sync::RwLock;
#[macro_use]
extern crate lazy_static;
lazy_static! {
static ref LANGS : RwLock<Localizer> = RwLock::new(
#[cfg(not(feature = "no_std"))]
{Localizer::create().res(res_keeper::new_file_from_path(None)).current_lang(Some("en".to_string())).user(&|x|{x.into_string();})},
#[cfg(feature = "no_std")]
{Localizer::create().current_lang(Some("en".to_string()))}
);
}
pub fn get_by_key(key : &str) -> Option<String>
{
LANGS.read().unwrap().get(key)
}
pub fn get_by_key1(val0 : String) -> String
{
get_by_key(&val0).unwrap_or(val0)
}
pub fn get_by_key2(key : &str, val2 : String) -> String
{
get_by_key(key).unwrap_or(val2)
}
#[cfg(feature = "format")]
pub fn get_form_by_key(key : &str, val2 : String, args : &dyn ContFormArgs ) -> String
{
let n = LANGS.read().unwrap();
n.get_f1(key, args).unwrap_or(val2)
}
pub fn get_by_key3(key : &str) -> Vec<String>
{
LANGS.read().unwrap().get1(key)
}
#[cfg(feature = "format")]
pub fn build<'a >(a : &[&'a dyn Display]) -> HashMap<String, &'a dyn Display> {
a.iter().enumerate().map(|(ind, x)| (format!("ind_{}", ind), *x)).collect()
}
pub fn change_localizer(f : &dyn Fn(&mut Localizer) -> ())
{
f(&mut LANGS.write().unwrap());
}
pub fn set_loc_string(string : &str)
{
change_localizer(&|x|{x.set_string(Some(string.to_string()));});
}
pub fn into_string()
{
change_localizer(&|x|{x.into_string();});
}
pub fn set_localizer(new : Localizer)
{
*LANGS.write().unwrap() = new;
}