diff options
| -rw-r--r-- | android/translations-converter/src/android.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/android/translations-converter/src/android.rs b/android/translations-converter/src/android.rs index e74562324a..8a4a89f91e 100644 --- a/android/translations-converter/src/android.rs +++ b/android/translations-converter/src/android.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; -use std::ops::{Deref, DerefMut}; +use std::{ + fmt::{self, Display, Formatter}, + ops::{Deref, DerefMut}, +}; /// Contents of an Android string resources file. /// @@ -52,3 +55,27 @@ impl IntoIterator for StringResources { self.entries.into_iter() } } + +// Unfortunately, direct serialization to XML isn't working correctly. +impl Display for StringResources { + fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { + writeln!(formatter, r#"<?xml version="1.0" encoding="utf-8"?>"#)?; + writeln!(formatter, "<resources>")?; + + for string in &self.entries { + writeln!(formatter, " {}", string)?; + } + + writeln!(formatter, "</resources>") + } +} + +impl Display for StringResource { + fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { + write!( + formatter, + r#"<string name="{}">{}</string>"#, + self.name, self.value + ) + } +} |
