summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/translations-converter/src/gettext.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/android/translations-converter/src/gettext.rs b/android/translations-converter/src/gettext.rs
index 24efcdfdf1..62f274d394 100644
--- a/android/translations-converter/src/gettext.rs
+++ b/android/translations-converter/src/gettext.rs
@@ -2,9 +2,11 @@ use lazy_static::lazy_static;
use regex::Regex;
use std::{
collections::BTreeMap,
+ fmt::{self, Display, Formatter},
fs::{File, OpenOptions},
io::{self, BufRead, BufReader, BufWriter, Write},
mem,
+ ops::Deref,
path::Path,
};
@@ -48,6 +50,10 @@ pub enum MsgValue {
},
}
+/// A message string in a gettext translation file.
+#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
+pub struct MsgString(String);
+
/// A helper macro to match a string to various prefix and suffix combinations.
macro_rules! match_str {
(
@@ -217,6 +223,33 @@ impl PluralForm {
}
}
+impl From<String> for MsgString {
+ fn from(string: String) -> Self {
+ MsgString(string)
+ }
+}
+
+impl From<&str> for MsgString {
+ fn from(string: &str) -> Self {
+ string.to_owned().into()
+ }
+}
+
+impl Display for MsgString {
+ /// Write the ID message string with proper escaping.
+ fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
+ self.0.replace(r#"""#, r#"\""#).fmt(formatter)
+ }
+}
+
+impl Deref for MsgString {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ self.0.as_str()
+ }
+}
+
impl From<String> for MsgValue {
fn from(string: String) -> Self {
MsgValue::Invariant(string)