Skip to content

Commit

Permalink
Fix bug 1491867: Add ability to wrap pseudolocale strings in markers (#…
Browse files Browse the repository at this point in the history
…225)

Also included:
* Ignore macOS .DS_Store files
* Bump version number to 0.2.4
  • Loading branch information
mathjazz committed Jul 19, 2021
1 parent e468ef5 commit fe50429
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
*/target/
**/*.rs.bk
Cargo.lock
.DS_Store
4 changes: 3 additions & 1 deletion fluent-pseudo/CHANGELOG.md
Expand Up @@ -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.

Expand All @@ -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.
2 changes: 1 addition & 1 deletion fluent-pseudo/Cargo.toml
Expand Up @@ -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 <gandalf@mozilla.com>",
Expand Down
17 changes: 13 additions & 4 deletions fluent-pseudo/src/lib.rs
Expand Up @@ -23,7 +23,7 @@ static FLIPPED_CAPS_MAP: &[char] = &[
static mut RE_EXCLUDED: Option<Regex> = None;
static mut RE_AZ: Option<Regex> = None;

pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
pub fn transform_dom(s: &str, flipped: bool, elongate: bool, with_markers: bool) -> Cow<str> {
// Exclude access-keys and other single-char messages
if s.len() == 1 {
return s.into();
Expand Down Expand Up @@ -56,6 +56,11 @@ pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
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
}

Expand Down Expand Up @@ -113,14 +118,18 @@ mod tests {

#[test]
fn dom_test() {
let x = transform_dom("Hello <a>World</a>", false, true);
let x = transform_dom("Hello <a>World</a>", false, true, false);
assert_eq!(x, "Ħeeŀŀoo <a>Ẇoořŀḓ</a>");

let x = transform_dom("Hello <a>World</a> in <b>my</b> House.", false, true);
let x = transform_dom("Hello <a>World</a> in <b>my</b> House.", false, true, false);
assert_eq!(x, "Ħeeŀŀoo <a>Ẇoořŀḓ</a> iƞ <b>ḿẏ</b> Ħ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");
}
}

0 comments on commit fe50429

Please sign in to comment.