Skip to main content

proto_types/common/
localized_text.rs

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