summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-09-10 21:34:54 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-10 18:30:28 +0000
commitdeae5310089c99d45754079d0ca381ef14c6d5e7 (patch)
tree6155c667937aabda412b26fa120c445e666be979
parent093f2ad6ef983dbbac4cfbb381fcd0917b86bf03 (diff)
downloadmullvadvpn-deae5310089c99d45754079d0ca381ef14c6d5e7.tar.xz
mullvadvpn-deae5310089c99d45754079d0ca381ef14c6d5e7.zip
Rename `load_file` into `Translation::from_file`
-rw-r--r--android/translations-converter/src/gettext.rs64
-rw-r--r--android/translations-converter/src/main.rs2
2 files changed, 34 insertions, 32 deletions
diff --git a/android/translations-converter/src/gettext.rs b/android/translations-converter/src/gettext.rs
index 342a77f4f2..1f0f19fe9c 100644
--- a/android/translations-converter/src/gettext.rs
+++ b/android/translations-converter/src/gettext.rs
@@ -33,6 +33,39 @@ pub enum MsgValue {
},
}
+impl Translation {
+ /// Load message entries from a gettext translation file.
+ ///
+ /// The messages are normalized into a common format so that they can be compared to Android
+ /// string resource entries.
+ pub fn from_file(file_path: impl AsRef<Path>) -> Self {
+ let mut entries = Vec::new();
+ let mut current_id = None;
+ let file = BufReader::new(File::open(file_path).expect("Failed to open gettext file"));
+
+ for line in file.lines() {
+ let line = line.expect("Failed to read from gettext file");
+ let line = line.trim();
+
+ if let Some(msg_id) = parse_line(line, "msgid \"", "\"") {
+ current_id = Some(normalize(msg_id));
+ } else {
+ if let Some(translation) = parse_line(line, "msgstr \"", "\"") {
+ if let Some(id) = current_id.take() {
+ let value = MsgValue::from(normalize(translation));
+
+ entries.push(MsgEntry { id, value });
+ }
+ }
+
+ current_id = None;
+ }
+ }
+
+ Self { entries }
+ }
+}
+
impl IntoIterator for Translation {
type Item = MsgEntry;
type IntoIter = std::vec::IntoIter<Self::Item>;
@@ -48,37 +81,6 @@ impl From<String> for MsgValue {
}
}
-/// Load message entries from a gettext translation file.
-///
-/// The messages are normalized into a common format so that they can be compared to Android string
-/// resource entries.
-pub fn load_file(file_path: impl AsRef<Path>) -> Translation {
- let mut entries = Vec::new();
- let mut current_id = None;
- let file = BufReader::new(File::open(file_path).expect("Failed to open gettext file"));
-
- for line in file.lines() {
- let line = line.expect("Failed to read from gettext file");
- let line = line.trim();
-
- if let Some(msg_id) = parse_line(line, "msgid \"", "\"") {
- current_id = Some(normalize(msg_id));
- } else {
- if let Some(translation) = parse_line(line, "msgstr \"", "\"") {
- if let Some(id) = current_id.take() {
- let value = MsgValue::from(normalize(translation));
-
- entries.push(MsgEntry { id, value });
- }
- }
-
- current_id = None;
- }
- }
-
- Translation { entries }
-}
-
/// Append message entries to a translation file.
///
/// This is used to append missing translation entries back to the base translation template file.
diff --git a/android/translations-converter/src/main.rs b/android/translations-converter/src/main.rs
index 08b90967f8..5ba5fa4790 100644
--- a/android/translations-converter/src/main.rs
+++ b/android/translations-converter/src/main.rs
@@ -101,7 +101,7 @@ fn main() {
locale,
known_urls.clone(),
known_strings.clone(),
- gettext::load_file(&locale_file),
+ gettext::Translation::from_file(&locale_file),
destination_dir.join("strings.xml"),
&mut missing_translations,
);