summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-05-10 20:18:41 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-05-19 12:13:36 +0000
commitb95c734b19931709c9f0fcacff1e92d6babdddba (patch)
tree0f21e70fff2112d4e36be03f5bdaa5811b9dc71a
parentd15541df914c50805062da1b489e43dceb11d593 (diff)
downloadmullvadvpn-b95c734b19931709c9f0fcacff1e92d6babdddba.tar.xz
mullvadvpn-b95c734b19931709c9f0fcacff1e92d6babdddba.zip
Remove previous Android string normalization
-rw-r--r--android/translations-converter/src/android/string_value.rs29
-rw-r--r--android/translations-converter/src/android/strings.rs16
-rw-r--r--android/translations-converter/src/main.rs7
3 files changed, 3 insertions, 49 deletions
diff --git a/android/translations-converter/src/android/string_value.rs b/android/translations-converter/src/android/string_value.rs
index c07967179c..7100b034aa 100644
--- a/android/translations-converter/src/android/string_value.rs
+++ b/android/translations-converter/src/android/string_value.rs
@@ -1,22 +1,10 @@
-use lazy_static::lazy_static;
-use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Display, Formatter},
ops::Deref,
};
-lazy_static! {
- static ref LINE_BREAKS: Regex = Regex::new(r"\s*\n\s*").unwrap();
- static ref APOSTROPHES: Regex = Regex::new(r"\\'").unwrap();
- static ref DOUBLE_QUOTES: Regex = Regex::new(r#"\\""#).unwrap();
- static ref PARAMETERS: Regex = Regex::new(r"%[0-9]*\$").unwrap();
-}
-
/// An Android string value
-///
-/// Handles escaping the string when it is created but also allows normalizing it for comparing it
-/// with gettext messages through a `normalize` method.
#[derive(Clone, Debug, Eq, Deserialize, Hash, PartialEq, Serialize)]
pub struct StringValue(String);
@@ -40,23 +28,6 @@ impl From<&str> for StringValue {
}
impl StringValue {
- /// Normalize the string value into a common format.
- ///
- /// Makes it possible to compare the Android strings with the gettext messages.
- pub fn normalize(&mut self) {
- // Collapse line breaks present in the XML file
- let value = LINE_BREAKS.replace_all(&self.0, " ");
- // Unescape apostrophes
- let value = APOSTROPHES.replace_all(&value, "'");
- // Unescape double quotes
- let value = DOUBLE_QUOTES.replace_all(&value, r#"""#);
- // Mark where parameters are positioned, removing the parameter index
- let value = PARAMETERS.replace_all(&value, "%");
-
- // Unescape XML characters
- self.0 = htmlize::unescape(value.as_bytes());
- }
-
/// Clones the internal string value.
pub fn to_string(&self) -> String {
self.0.clone()
diff --git a/android/translations-converter/src/android/strings.rs b/android/translations-converter/src/android/strings.rs
index 3ef0dabc8f..da9923db6f 100644
--- a/android/translations-converter/src/android/strings.rs
+++ b/android/translations-converter/src/android/strings.rs
@@ -37,15 +37,6 @@ impl StringResources {
}
}
- /// Normalize the strings into a common format.
- ///
- /// Allows the string values to be compared to the gettext messages.
- pub fn normalize(&mut self) {
- for entry in &mut self.entries {
- entry.normalize();
- }
- }
-
/// Sorts the entries alphabetically based on their IDs.
pub fn sort(&mut self) {
self.entries
@@ -87,13 +78,6 @@ impl StringResource {
value: StringValue::from(value),
}
}
-
- /// Normalize the string value into a common format.
- ///
- /// Makes it possible to compare the Android strings with the gettext messages.
- pub fn normalize(&mut self) {
- self.value.normalize();
- }
}
fn default_translatable() -> bool {
diff --git a/android/translations-converter/src/main.rs b/android/translations-converter/src/main.rs
index 847d95ff54..b5fb61838c 100644
--- a/android/translations-converter/src/main.rs
+++ b/android/translations-converter/src/main.rs
@@ -35,6 +35,7 @@ mod android;
mod gettext;
mod normalize;
+use crate::normalize::Normalize;
use std::{
collections::HashMap,
fs::{self, File},
@@ -46,15 +47,13 @@ fn main() {
let strings_file = File::open(resources_dir.join("values/strings.xml"))
.expect("Failed to open string resources file");
- let mut string_resources: android::StringResources =
+ let string_resources: android::StringResources =
serde_xml_rs::from_reader(strings_file).expect("Failed to read string resources file");
- string_resources.normalize();
-
let (known_urls, known_strings): (HashMap<_, _>, HashMap<_, _>) = string_resources
.into_iter()
.filter(|resource| resource.translatable)
- .map(|resource| (resource.value.to_string(), resource.name))
+ .map(|resource| (resource.value.normalize(), resource.name))
.partition(|(string, _id)| string.starts_with("https://mullvad.net/en/"));
let plurals_file = File::open(resources_dir.join("values/plurals.xml"))