diff --git a/.gitignore b/.gitignore index 4bf6b093..307735b2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ */target/ **/*.rs.bk Cargo.lock +.DS_Store diff --git a/fluent-pseudo/CHANGELOG.md b/fluent-pseudo/CHANGELOG.md index 39f58487..7f93ae6d 100644 --- a/fluent-pseudo/CHANGELOG.md +++ b/fluent-pseudo/CHANGELOG.md @@ -4,6 +4,9 @@ - … +## fluent-pseudo 0.2.4 (July 19, 2021) + - Ability to wrap strings in markers. + ## fluent-pseudo 0.2.3 (November 12, 2020) - Improve readability of the accented pseudo. @@ -17,6 +20,5 @@ - Update `regex` to 1.3. ## fluent-pseudo 0.0.1 (August 1, 2019) - - This is the first release to be listed in the CHANGELOG. - Basic support for pseudo-localization matching the fluent.js capabilities. diff --git a/fluent-pseudo/Cargo.toml b/fluent-pseudo/Cargo.toml index 41a81f70..8bbd8f2c 100644 --- a/fluent-pseudo/Cargo.toml +++ b/fluent-pseudo/Cargo.toml @@ -3,7 +3,7 @@ name = "fluent-pseudo" description = """ Pseudolocalization transformation API for use with Project Fluent API. """ -version = "0.2.3" +version = "0.2.4" edition = "2018" authors = [ "Zibi Braniecki ", diff --git a/fluent-pseudo/src/lib.rs b/fluent-pseudo/src/lib.rs index 0c9466ec..607b91ea 100644 --- a/fluent-pseudo/src/lib.rs +++ b/fluent-pseudo/src/lib.rs @@ -23,7 +23,7 @@ static FLIPPED_CAPS_MAP: &[char] = &[ static mut RE_EXCLUDED: Option = None; static mut RE_AZ: Option = None; -pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow { +pub fn transform_dom(s: &str, flipped: bool, elongate: bool, with_markers: bool) -> Cow { // Exclude access-keys and other single-char messages if s.len() == 1 { return s.into(); @@ -56,6 +56,11 @@ pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow { let result_range = pos + diff..result.len(); let transform_sub = transform(&s[range], flipped, elongate); result.to_mut().replace_range(result_range, &transform_sub); + + if with_markers { + return Cow::from("[") + result + "]" + } + result } @@ -113,14 +118,18 @@ mod tests { #[test] fn dom_test() { - let x = transform_dom("Hello World", false, true); + let x = transform_dom("Hello World", false, true, false); assert_eq!(x, "Ħeeŀŀoo Ẇoořŀḓ"); - let x = transform_dom("Hello World in my House.", false, true); + let x = transform_dom("Hello World in my House.", false, true, false); assert_eq!(x, "Ħeeŀŀoo Ẇoořŀḓḿẏ Ħoouuşee."); + // Use markers. + let x = transform_dom("Hello World within markers", false, false, true); + assert_eq!(x, "[Ħeŀŀo Ẇořŀḓ ẇiŧħiƞ ḿařķeřş]"); + // Don't touch single character values. - let x = transform_dom("f", false, true); + let x = transform_dom("f", false, true, false); assert_eq!(x, "f"); } }