1use std::fmt::{self, Display};
2use serde::{Serialize, Deserialize};
3
4
5#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
6pub enum Language {
7 #[serde(rename="ar")]
8 Arabic,
9 #[serde(rename="bn")]
10 Bengali,
11 #[serde(rename="bg")]
12 Bulgarian,
13 #[serde(rename="zh")]
14 ChineseSimplified,
15 #[serde(rename="zh_tw")]
16 ChineseTraditional,
17 #[serde(rename="cs")]
18 Czech,
19 #[serde(rename="da")]
20 Danish,
21 #[serde(rename="nl")]
22 Dutch,
23 #[serde(rename="fi")]
24 Finnish,
25 #[serde(rename="fr")]
26 French,
27 #[serde(rename="de")]
28 German,
29 #[serde(rename="el")]
30 Greek,
31 #[serde(rename="hi")]
32 Hindi,
33 #[serde(rename="hu")]
34 Hungarian,
35 #[serde(rename="it")]
36 Italian,
37 #[serde(rename="ja")]
38 Japanese,
39 #[serde(rename="jv")]
40 Javanese,
41 #[serde(rename="ko")]
42 Korean,
43 #[serde(rename="zh_cmn")]
44 Mandarin,
45 #[serde(rename="mr")]
46 Marathi,
47 #[serde(rename="pl")]
48 Polish,
49 #[serde(rename="pt")]
50 Portuguese,
51 #[serde(rename="pa")]
52 Punjabi,
53 #[serde(rename="ro")]
54 Romanian,
55 #[serde(rename="ru")]
56 Russian,
57 #[serde(rename="sr")]
58 Serbian,
59 #[serde(rename="si")]
60 Sinhalese,
61 #[serde(rename="sk")]
62 Slovak,
63 #[serde(rename="es")]
64 Spanish,
65 #[serde(rename="sv")]
66 Swedish,
67 #[serde(rename="ta")]
68 Tamil,
69 #[serde(rename="te")]
70 Telugu,
71 #[serde(rename="tr")]
72 Turkish,
73 #[serde(rename="uk")]
74 Ukrainian,
75 #[serde(rename="ur")]
76 Urdu,
77 #[serde(rename="vi")]
78 Vietnamese,
79 #[serde(rename="zh_wuu")]
80 WuShanghainese,
81 #[serde(rename="zh_hsn")]
82 Xiang,
83 #[serde(rename="zh_yue")]
84 YueCantonese,
85 #[serde(rename="zu")]
86 Zulu
87}
88
89impl Language {
90 pub fn new(lang: &str) -> Result<Self, serde_json::Error> {
91 serde_json::from_value(serde_json::json![lang])
92 }
93
94 pub fn content(&self) -> &str {
95 match self {
96 Language::Arabic => "ar",
97 Language::Bengali => "bn",
98 Language::Bulgarian => "bg",
99 Language::ChineseSimplified => "zh",
100 Language::ChineseTraditional => "zh_tw",
101 Language::Czech => "cs",
102 Language::Danish => "da",
103 Language::Dutch => "nl",
104 Language::Finnish => "fi",
105 Language::French => "fr",
106 Language::German => "de",
107 Language::Greek => "el",
108 Language::Hindi => "hi",
109 Language::Hungarian => "hu",
110 Language::Italian => "it",
111 Language::Japanese => "ja",
112 Language::Javanese => "jv",
113 Language::Korean => "ko",
114 Language::Mandarin => "zh_cmn",
115 Language::Marathi => "mr",
116 Language::Polish => "pl",
117 Language::Portuguese => "pt",
118 Language::Punjabi => "pa",
119 Language::Romanian => "ro",
120 Language::Russian => "ru",
121 Language::Serbian => "sr",
122 Language::Sinhalese => "si",
123 Language::Slovak => "sk",
124 Language::Spanish => "es",
125 Language::Swedish => "sv",
126 Language::Tamil => "ta",
127 Language::Telugu => "te",
128 Language::Turkish => "tr",
129 Language::Ukrainian => "uk",
130 Language::Urdu => "ur",
131 Language::Vietnamese => "vi",
132 Language::WuShanghainese => "zh_wuu",
133 Language::Xiang => "zh_hsn",
134 Language::YueCantonese => "zh_yue",
135 Language::Zulu => "zu"
136 }
137 }
138}
139
140impl Display for Language {
141 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142 write!(f, "{}", self.content())
143 }
144}
145