diff --git a/Cargo.lock b/Cargo.lock index 5206b97b..79d706c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -184,7 +184,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -217,7 +217,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -234,7 +234,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -251,7 +251,7 @@ checksum = "edf3ee19dbc0a46d740f6f0926bde8c50f02bdbc7b536842da28f6ac56513a8b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -420,6 +420,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "casey" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614586263949597dcc18675da12ef9b429135e13628d92eb8b8c6fa50ca5656b" +dependencies = [ + "syn 1.0.109", +] + [[package]] name = "cast" version = "0.3.0" @@ -856,7 +865,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -922,7 +931,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -1182,7 +1191,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -1612,6 +1621,7 @@ name = "hemtt-stringtable" version = "1.0.0" dependencies = [ "automod", + "casey", "hemtt-common", "hemtt-workspace", "insta", @@ -1685,7 +1695,7 @@ dependencies = [ "markup5ever", "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -2027,7 +2037,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -2287,7 +2297,7 @@ checksum = "b01f197a15988fb5b2ec0a5a9800c97e70771499c456ad757d63b3c5e9b96e75" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -2649,7 +2659,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -2799,7 +2809,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -2929,7 +2939,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -3017,7 +3027,7 @@ checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -3152,7 +3162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30" dependencies = [ "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -3460,7 +3470,7 @@ checksum = "a5a11a05ee1ce44058fa3d5961d05194fdbe3ad6b40f904af764d81b86450e6b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -3529,7 +3539,7 @@ dependencies = [ "quote", "rust-embed-utils", "shellexpand", - "syn", + "syn 2.0.85", "walkdir", ] @@ -3674,7 +3684,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77253fb2d4451418d07025826028bcb96ee42d3e58859689a70ce62908009db6" dependencies = [ "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -3734,7 +3744,7 @@ checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -3757,7 +3767,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -4048,7 +4058,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.85", ] [[package]] @@ -4063,6 +4073,17 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c0a1e5168041f5f3ff68ff7d95dcb9c8749df29f6e7e89ada40dd4c9de404ee" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.85" @@ -4215,7 +4236,7 @@ checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -4330,7 +4351,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -4479,7 +4500,7 @@ checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -4508,7 +4529,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -4581,7 +4602,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04659ddb06c87d233c566112c1c9c5b9e98256d9af50ec3bc9c8327f873a7568" dependencies = [ "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -4830,7 +4851,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.85", "wasm-bindgen-shared", ] @@ -4864,7 +4885,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5266,7 +5287,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] @@ -5286,7 +5307,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.85", ] [[package]] diff --git a/libs/stringtable/Cargo.toml b/libs/stringtable/Cargo.toml index 04f02442..15196bea 100644 --- a/libs/stringtable/Cargo.toml +++ b/libs/stringtable/Cargo.toml @@ -13,6 +13,7 @@ hemtt-common = { path = "../common", version = "1.0.0" } hemtt-workspace = { path = "../workspace", version = "1.0.0" } automod = { workspace = true } +casey = "0.4" linkme = { workspace = true } paste = { workspace = true } quick-xml = { version = "0.37.0", features = ["serialize"] } diff --git a/libs/stringtable/src/key.rs b/libs/stringtable/src/key.rs index e3a5805c..37d4eb17 100644 --- a/libs/stringtable/src/key.rs +++ b/libs/stringtable/src/key.rs @@ -1,57 +1,92 @@ -use serde::{Deserialize, Serialize}; +use quick_xml::escape::minimal_escape; +use serde::{Deserialize, Serialize, Serializer}; + +fn min_escape(s: &Option, ser: S) -> Result +where + S: Serializer, +{ + match s { + Some(s) => ser.serialize_str(&minimal_escape(s)), + None => ser.serialize_none(), + } +} #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "PascalCase")] pub struct Key { #[serde(rename = "@ID")] id: String, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "original", alias = "ORIGINAL")] original: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "english", alias = "ENGLISH")] english: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "czech", alias = "CZECH")] czech: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "french", alias = "FRENCH")] french: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "spanish", alias = "SPANISH")] spanish: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "italian", alias = "ITALIAN")] italian: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "polish", alias = "POLISH")] polish: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "portuguese", alias = "PORTUGUESE")] portuguese: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "russian", alias = "RUSSIAN")] russian: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "german", alias = "GERMAN")] german: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "korean", alias = "KOREAN")] korean: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "japanese", alias = "JAPANESE")] japanese: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "chinese", alias = "CHINESE")] chinese: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "chinesesimp", alias = "CHINESESIMP")] chinesesimp: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "turkish", alias = "TURKISH")] turkish: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "swedish", alias = "SWEDISH")] swedish: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "slovak", alias = "SLOVAK")] slovak: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "serbocroatian", alias = "SERBOCROATIAN")] serbocroatian: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "norwegian", alias = "NORWEGIAN")] norwegian: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "icelandic", alias = "ICELANDIC")] icelandic: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "hungarian", alias = "HUNGARIAN")] hungarian: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "greek", alias = "GREEK")] greek: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "finnish", alias = "FINNISH")] finnish: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none", serialize_with = "min_escape")] + #[serde(alias = "dutch", alias = "DUTCH")] dutch: Option, } diff --git a/libs/stringtable/src/lib.rs b/libs/stringtable/src/lib.rs index 745e5e2b..cabe7bb5 100644 --- a/libs/stringtable/src/lib.rs +++ b/libs/stringtable/src/lib.rs @@ -89,7 +89,7 @@ impl Project { in_key = None; } } - Ok(l) + Ok(l.replace('&', "&")) }) .collect::, _>>() else { @@ -115,6 +115,7 @@ impl Project { let mut buffer = String::new(); let mut ser = Serializer::new(&mut buffer); ser.indent(' ', 4); + ser.expand_empty_elements(true); self.serialize(ser)?; buffer.push('\n'); @@ -140,7 +141,8 @@ impl Project { writer.write_char('\n')?; } } - writer.write_str(line)?; + println!("{}", line); + writer.write_str(line.replace("&", "&").as_str())?; writer.write_char('\n')?; if l_trim.starts_with(""' "' "' + "Hello World" diff --git a/libs/stringtable/tests/gh882_out.xml b/libs/stringtable/tests/gh882_out.xml index dbe72cd6..4bacba7b 100644 --- a/libs/stringtable/tests/gh882_out.xml +++ b/libs/stringtable/tests/gh882_out.xml @@ -9,18 +9,25 @@ - + + hey + hey + hey + hey + + - - - - + + + + - "' - "' - "' - "' + "' + "' + "Hello World" + "' + "' - + + hey + hey + hey + hey + + - - - - + + + + - "' - "' - "' - "' + "' + "' + "Hello World" + "' + "'