rust_tdlib/types/
language_pack_info.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Contains information about a language pack
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct LanguagePackInfo {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Unique language pack identifier
14
15    #[serde(default)]
16    id: String,
17    /// Identifier of a base language pack; may be empty. If a string is missed in the language pack, then it must be fetched from base language pack. Unsupported in custom language packs
18
19    #[serde(default)]
20    base_language_pack_id: String,
21    /// Language name
22
23    #[serde(default)]
24    name: String,
25    /// Name of the language in that language
26
27    #[serde(default)]
28    native_name: String,
29    /// A language code to be used to apply plural forms. See https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html for more info
30
31    #[serde(default)]
32    plural_code: String,
33    /// True, if the language pack is official
34
35    #[serde(default)]
36    is_official: bool,
37    /// True, if the language pack strings are RTL
38
39    #[serde(default)]
40    is_rtl: bool,
41    /// True, if the language pack is a beta language pack
42
43    #[serde(default)]
44    is_beta: bool,
45    /// True, if the language pack is installed by the current user
46
47    #[serde(default)]
48    is_installed: bool,
49    /// Total number of non-deleted strings from the language pack
50
51    #[serde(default)]
52    total_string_count: i32,
53    /// Total number of translated strings from the language pack
54
55    #[serde(default)]
56    translated_string_count: i32,
57    /// Total number of non-deleted strings from the language pack available locally
58
59    #[serde(default)]
60    local_string_count: i32,
61    /// Link to language translation interface; empty for custom local language packs
62
63    #[serde(default)]
64    translation_url: String,
65}
66
67impl RObject for LanguagePackInfo {
68    #[doc(hidden)]
69    fn extra(&self) -> Option<&str> {
70        self.extra.as_deref()
71    }
72    #[doc(hidden)]
73    fn client_id(&self) -> Option<i32> {
74        self.client_id
75    }
76}
77
78impl LanguagePackInfo {
79    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
80        Ok(serde_json::from_str(json.as_ref())?)
81    }
82    pub fn builder() -> LanguagePackInfoBuilder {
83        let mut inner = LanguagePackInfo::default();
84        inner.extra = Some(Uuid::new_v4().to_string());
85
86        LanguagePackInfoBuilder { inner }
87    }
88
89    pub fn id(&self) -> &String {
90        &self.id
91    }
92
93    pub fn base_language_pack_id(&self) -> &String {
94        &self.base_language_pack_id
95    }
96
97    pub fn name(&self) -> &String {
98        &self.name
99    }
100
101    pub fn native_name(&self) -> &String {
102        &self.native_name
103    }
104
105    pub fn plural_code(&self) -> &String {
106        &self.plural_code
107    }
108
109    pub fn is_official(&self) -> bool {
110        self.is_official
111    }
112
113    pub fn is_rtl(&self) -> bool {
114        self.is_rtl
115    }
116
117    pub fn is_beta(&self) -> bool {
118        self.is_beta
119    }
120
121    pub fn is_installed(&self) -> bool {
122        self.is_installed
123    }
124
125    pub fn total_string_count(&self) -> i32 {
126        self.total_string_count
127    }
128
129    pub fn translated_string_count(&self) -> i32 {
130        self.translated_string_count
131    }
132
133    pub fn local_string_count(&self) -> i32 {
134        self.local_string_count
135    }
136
137    pub fn translation_url(&self) -> &String {
138        &self.translation_url
139    }
140}
141
142#[doc(hidden)]
143pub struct LanguagePackInfoBuilder {
144    inner: LanguagePackInfo,
145}
146
147#[deprecated]
148pub type RTDLanguagePackInfoBuilder = LanguagePackInfoBuilder;
149
150impl LanguagePackInfoBuilder {
151    pub fn build(&self) -> LanguagePackInfo {
152        self.inner.clone()
153    }
154
155    pub fn id<T: AsRef<str>>(&mut self, id: T) -> &mut Self {
156        self.inner.id = id.as_ref().to_string();
157        self
158    }
159
160    pub fn base_language_pack_id<T: AsRef<str>>(&mut self, base_language_pack_id: T) -> &mut Self {
161        self.inner.base_language_pack_id = base_language_pack_id.as_ref().to_string();
162        self
163    }
164
165    pub fn name<T: AsRef<str>>(&mut self, name: T) -> &mut Self {
166        self.inner.name = name.as_ref().to_string();
167        self
168    }
169
170    pub fn native_name<T: AsRef<str>>(&mut self, native_name: T) -> &mut Self {
171        self.inner.native_name = native_name.as_ref().to_string();
172        self
173    }
174
175    pub fn plural_code<T: AsRef<str>>(&mut self, plural_code: T) -> &mut Self {
176        self.inner.plural_code = plural_code.as_ref().to_string();
177        self
178    }
179
180    pub fn is_official(&mut self, is_official: bool) -> &mut Self {
181        self.inner.is_official = is_official;
182        self
183    }
184
185    pub fn is_rtl(&mut self, is_rtl: bool) -> &mut Self {
186        self.inner.is_rtl = is_rtl;
187        self
188    }
189
190    pub fn is_beta(&mut self, is_beta: bool) -> &mut Self {
191        self.inner.is_beta = is_beta;
192        self
193    }
194
195    pub fn is_installed(&mut self, is_installed: bool) -> &mut Self {
196        self.inner.is_installed = is_installed;
197        self
198    }
199
200    pub fn total_string_count(&mut self, total_string_count: i32) -> &mut Self {
201        self.inner.total_string_count = total_string_count;
202        self
203    }
204
205    pub fn translated_string_count(&mut self, translated_string_count: i32) -> &mut Self {
206        self.inner.translated_string_count = translated_string_count;
207        self
208    }
209
210    pub fn local_string_count(&mut self, local_string_count: i32) -> &mut Self {
211        self.inner.local_string_count = local_string_count;
212        self
213    }
214
215    pub fn translation_url<T: AsRef<str>>(&mut self, translation_url: T) -> &mut Self {
216        self.inner.translation_url = translation_url.as_ref().to_string();
217        self
218    }
219}
220
221impl AsRef<LanguagePackInfo> for LanguagePackInfo {
222    fn as_ref(&self) -> &LanguagePackInfo {
223        self
224    }
225}
226
227impl AsRef<LanguagePackInfo> for LanguagePackInfoBuilder {
228    fn as_ref(&self) -> &LanguagePackInfo {
229        &self.inner
230    }
231}