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
use core::panic;
use std::fmt;
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct Lang {
lang: &'static str,
}
impl Lang {
const SUPPORTED_LANG: &'static [&'static str] = &[
"af", "ga", "sq", "it", "ar", "ja", "az", "kn", "eu", "ko", "bn", "la", "be", "lv", "bg",
"lt", "ca", "mk", "zh-CN", "ms", "zh-TW", "mt", "hr", "no", "cs", "fa", "da", "pl", "nl",
"pt", "en", "ro", "eo", "ru", "et", "sr", "tl", "sk", "fi", "sl", "fr", "es", "gl", "sw",
"ka", "sv", "de", "ta", "el", "te", "gu", "th", "ht", "tr", "iw", "uk", "hi", "ur", "hu",
"vi", "is", "cy", "id", "yi",
];
pub fn new(lang: &'static str) -> Lang {
Lang {
lang: Self::check_lang(lang),
}
}
fn check_lang(lang: &'static str) -> &'static str {
match Self::SUPPORTED_LANG.contains(&lang) {
true => lang,
false => panic!("Unsupported langage !"),
}
}
pub fn as_str(&self) -> &'static str {
self.lang
}
pub fn list() {
println!("{:#?}", Self::SUPPORTED_LANG);
}
}
impl fmt::Display for Lang {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.lang)
}
}