diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-09-10 20:40:12 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-12-10 18:30:27 +0000 |
| commit | 093f2ad6ef983dbbac4cfbb381fcd0917b86bf03 (patch) | |
| tree | 6bf92310e9ed78477938cf19bb50d663b52bfda2 /android | |
| parent | a688883883a567b6be0d331fac4006d2b610eb9c (diff) | |
| download | mullvadvpn-093f2ad6ef983dbbac4cfbb381fcd0917b86bf03.tar.xz mullvadvpn-093f2ad6ef983dbbac4cfbb381fcd0917b86bf03.zip | |
Create `gettext::Translation` type
Diffstat (limited to 'android')
| -rw-r--r-- | android/translations-converter/src/gettext.rs | 18 | ||||
| -rw-r--r-- | android/translations-converter/src/main.rs | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/android/translations-converter/src/gettext.rs b/android/translations-converter/src/gettext.rs index 26abdbd577..342a77f4f2 100644 --- a/android/translations-converter/src/gettext.rs +++ b/android/translations-converter/src/gettext.rs @@ -11,6 +11,11 @@ lazy_static! { static ref PARAMETERS: Regex = Regex::new(r"%\([^)]*\)").unwrap(); } +/// A parsed gettext translation file. +pub struct Translation { + entries: Vec<MsgEntry>, +} + /// A message entry in a gettext translation file. #[derive(Clone, Debug)] pub struct MsgEntry { @@ -28,6 +33,15 @@ pub enum MsgValue { }, } +impl IntoIterator for Translation { + type Item = MsgEntry; + type IntoIter = std::vec::IntoIter<Self::Item>; + + fn into_iter(self) -> Self::IntoIter { + self.entries.into_iter() + } +} + impl From<String> for MsgValue { fn from(string: String) -> Self { MsgValue::Invariant(string) @@ -38,7 +52,7 @@ impl From<String> for MsgValue { /// /// 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>) -> Vec<MsgEntry> { +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")); @@ -62,7 +76,7 @@ pub fn load_file(file_path: impl AsRef<Path>) -> Vec<MsgEntry> { } } - entries + Translation { entries } } /// Append message entries to a translation file. diff --git a/android/translations-converter/src/main.rs b/android/translations-converter/src/main.rs index 36a1970c2d..08b90967f8 100644 --- a/android/translations-converter/src/main.rs +++ b/android/translations-converter/src/main.rs @@ -188,7 +188,7 @@ fn generate_translations( locale: &str, known_urls: HashMap<String, String>, mut known_strings: HashMap<String, String>, - translations: Vec<gettext::MsgEntry>, + translations: gettext::Translation, output_path: impl AsRef<Path>, missing_translations: &mut HashMap<String, String>, ) { |
