diff options
| author | David Göransson <david.goransson@mullvad.net> | 2025-03-21 14:57:29 +0100 |
|---|---|---|
| committer | David Göransson <david.goransson@mullvad.net> | 2025-03-24 13:35:53 +0100 |
| commit | 43e04751fbf953e87c09cf91fcd0a8e2fc8f9822 (patch) | |
| tree | b60996dfef30e3ac7ab5de8a766bb0eee4fd4c11 /android | |
| parent | 38074c3ef02f9a8166081411637fd38055d3ffea (diff) | |
| download | mullvadvpn-43e04751fbf953e87c09cf91fcd0a8e2fc8f9822.tar.xz mullvadvpn-43e04751fbf953e87c09cf91fcd0a8e2fc8f9822.zip | |
Prevent duplicate string values in Android xml
Diffstat (limited to 'android')
| -rw-r--r-- | android/translations-converter/Cargo.toml | 1 | ||||
| -rw-r--r-- | android/translations-converter/src/main.rs | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/android/translations-converter/Cargo.toml b/android/translations-converter/Cargo.toml index 67704daf2c..3cb9176496 100644 --- a/android/translations-converter/Cargo.toml +++ b/android/translations-converter/Cargo.toml @@ -16,3 +16,4 @@ htmlize = { version = "1.0.2", features = ["unescape"] } regex = "1" serde = { workspace = true, features = ["derive"] } quick-xml = { version = "0.27.1", features = ["serialize"] } +itertools = "0.14.0" diff --git a/android/translations-converter/src/main.rs b/android/translations-converter/src/main.rs index da5b6e3a27..314bbf3e44 100644 --- a/android/translations-converter/src/main.rs +++ b/android/translations-converter/src/main.rs @@ -35,8 +35,10 @@ mod android; mod gettext; mod normalize; +use crate::android::{StringResource, StringValue}; use crate::gettext::MsgValue; use crate::normalize::Normalize; +use itertools::Itertools; use std::{ collections::HashMap, fs::{self, File}, @@ -53,6 +55,32 @@ fn main() { quick_xml::de::from_reader(BufReader::new(strings_file)) .expect("Failed to read string resources file"); + // The current format is not built to handle multiple strings with the same values + // so we check for duplicates and panic if they are present + let duplicates: HashMap<&StringValue, Vec<&StringResource>> = string_resources + .iter() + .into_group_map_by(|res| &res.value) + .into_iter() + .filter(|(_, string_resources)| string_resources.len() > 1) + .collect(); + + if !duplicates.is_empty() { + duplicates + .iter() + .for_each(|(string_value, string_resources)| { + eprintln!( + "String value: '{}', exists in following resource IDs: {}", + string_value, + string_resources + .iter() + .map(|x| x.name.clone()) + .collect::<Vec<_>>() + .join(", ") + ) + }); + panic!("Duplicate string values!!"); + } + let known_strings: HashMap<_, _> = string_resources .into_iter() .map(|resource| (resource.value.normalize(), resource.name)) |
