summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-08-19 21:13:58 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-08-24 19:19:38 +0000
commit9169de8c6284445e75897dd1abaccc150c181dcf (patch)
tree2b952d005d3bf684cb664ee7f23e53ccdcaf3fa4
parente6b0f6112e9dd825f2aacd66b39d9120e7cdc5a6 (diff)
downloadmullvadvpn-9169de8c6284445e75897dd1abaccc150c181dcf.tar.xz
mullvadvpn-9169de8c6284445e75897dd1abaccc150c181dcf.zip
Implement parsing of Android plural resources
-rw-r--r--android/translations-converter/src/android.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/android/translations-converter/src/android.rs b/android/translations-converter/src/android.rs
index 10293aab8a..ca759ffb1e 100644
--- a/android/translations-converter/src/android.rs
+++ b/android/translations-converter/src/android.rs
@@ -158,3 +158,68 @@ impl Display for StringResource {
}
}
}
+
+/// Contents of an Android plurals resources file.
+///
+/// This type can be created directly deserializing the `plurals.xml` file.
+#[derive(Clone, Debug, Deserialize, Serialize)]
+pub struct PluralResources {
+ #[serde(rename = "plurals")]
+ entries: Vec<PluralResource>,
+}
+
+/// An entry in an Android plurals resources file.
+#[derive(Clone, Debug, Deserialize, Serialize)]
+pub struct PluralResource {
+ /// The plural resource ID.
+ pub name: String,
+
+ /// The items of the plural resource, one for each quantity variant.
+ #[serde(rename = "item")]
+ pub items: Vec<PluralVariant>,
+}
+
+/// A string resource for a specific quantity.
+///
+/// This is part of a plural resource.
+#[derive(Clone, Debug, Deserialize, Serialize)]
+pub struct PluralVariant {
+ /// The quantity for this variant to be used.
+ pub quantity: PluralQuantity,
+
+ /// The string value
+ #[serde(rename = "$value")]
+ pub string: String,
+}
+
+/// A valid quantity for a plural variant.
+#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum PluralQuantity {
+ Zero,
+ One,
+ Other,
+}
+
+impl Deref for PluralResources {
+ type Target = Vec<PluralResource>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.entries
+ }
+}
+
+impl DerefMut for PluralResources {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.entries
+ }
+}
+
+impl IntoIterator for PluralResources {
+ type Item = PluralResource;
+ type IntoIter = std::vec::IntoIter<Self::Item>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.entries.into_iter()
+ }
+}