proto_types/common/localized_text.rs
1use crate::common::LocalizedText;
2
3impl LocalizedText {
4 /// Checks if the language code matches the given input.
5 pub fn has_code(&self, code: &str) -> bool {
6 self.language_code == code
7 }
8
9 /// Checks if the language code is for English.
10 /// This method checks for the primary 'en' subtag.
11 pub fn is_en(&self) -> bool {
12 self.language_code.starts_with("en")
13 }
14
15 /// Checks if the language code is for Spanish.
16 /// This method checks for the primary 'es' subtag.
17 pub fn is_es(&self) -> bool {
18 self.language_code.starts_with("es")
19 }
20
21 /// Checks if the language code is for French.
22 /// This method checks for the primary 'fr' subtag.
23 pub fn is_fr(&self) -> bool {
24 self.language_code.starts_with("fr")
25 }
26
27 /// Checks if the language code is for German.
28 /// This method checks for the primary 'de' subtag.
29 pub fn is_de(&self) -> bool {
30 self.language_code.starts_with("de")
31 }
32
33 /// Checks if the language code is for Simplified Chinese (zh-Hans).
34 /// This method specifically looks for "zh-Hans".
35 pub fn is_zh_hans(&self) -> bool {
36 self.language_code == "zh-Hans"
37 }
38
39 /// Checks if the language code is for Traditional Chinese (zh-Hant).
40 /// This method specifically looks for "zh-Hant".
41 pub fn is_zh_hant(&self) -> bool {
42 self.language_code == "zh-Hant"
43 }
44
45 /// Checks if the language code is for Hindi.
46 /// This method checks for the primary 'hi' subtag.
47 pub fn is_hi(&self) -> bool {
48 self.language_code.starts_with("hi")
49 }
50
51 /// Checks if the language code is for Portuguese.
52 /// This method checks for the primary 'pt' subtag.
53 pub fn is_pt(&self) -> bool {
54 self.language_code.starts_with("pt")
55 }
56
57 /// Checks if the language code is for Russian.
58 /// This method checks for the primary 'ru' subtag.
59 pub fn is_ru(&self) -> bool {
60 self.language_code.starts_with("ru")
61 }
62
63 /// Checks if the language code is for Japanese.
64 /// This method checks for the primary 'ja' subtag.
65 pub fn is_ja(&self) -> bool {
66 self.language_code.starts_with("ja")
67 }
68
69 /// Checks if the language code is for Arabic.
70 /// This method checks for the primary 'ar' subtag.
71 pub fn is_ar(&self) -> bool {
72 self.language_code.starts_with("ar")
73 }
74
75 /// Checks if the language code is for Italian.
76 /// This method checks for the primary 'it' subtag.
77 pub fn is_it(&self) -> bool {
78 self.language_code.starts_with("it")
79 }
80}