Backed out 3 changesets (bug 1675789) for test_pseudo.js failures CLOSED TREE

Backed out changeset 96add4c0a255 (bug 1675789)
Backed out changeset 0e0fe4161436 (bug 1675789)
Backed out changeset dcd4e0412d54 (bug 1675789)
This commit is contained in:
Bogdan Tara 2020-11-13 04:21:54 +02:00
parent 0038aea648
commit 944e17a779
8 changed files with 39 additions and 26 deletions

4
Cargo.lock generated
View File

@ -1545,9 +1545,9 @@ dependencies = [
[[package]]
name = "fluent-pseudo"
version = "0.2.3"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f028d6802c52903b3d8fa1cc37264ae5b8b630161e600eccfa68d4ee6ce5163a"
checksum = "ca3a870aefc42d175d11fb1ec089221ced8a160d66ca1e0c64a57b4ae90d2462"
dependencies = [
"regex",
]

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies]
fluent = { version = "0.13.1", features = ["fluent-pseudo"] }
fluent-pseudo = "0.2.3"
fluent-pseudo = "0.2"
intl-memoizer = "0.5"
unic-langid = "0.9"
nsstring = { path = "../../../../xpcom/rust/nsstring" }

View File

@ -28,7 +28,7 @@ fn transform_accented(s: &str) -> Cow<str> {
}
fn transform_bidi(s: &str) -> Cow<str> {
transform_dom(s, false, false)
transform_dom(s, true, false)
}
fn format_numbers(num: &FluentValue, intls: &IntlLangMemoizer) -> Option<String> {

View File

@ -1 +1 @@
{"files":{"Cargo.toml":"e8314d0278f83d921d2cf1777ddda0ea476621e6b217c60fef018d6555819553","README.md":"c724fbe817e1370765c91bd14e35486ff43a58214598202eafe70fd35f3a785d","src/lib.rs":"ae1cb5330baa8d6a875d834c614d7f42f8ab57dbcf5f2baf2276c90eb671c4f2"},"package":"f028d6802c52903b3d8fa1cc37264ae5b8b630161e600eccfa68d4ee6ce5163a"}
{"files":{"CHANGELOG.md":"643031d0ea21e0539305186fa41c5fb57889f28c49f1fc27c75b4f659522773c","Cargo.toml":"7f0730a670b8ac4edf2e8ead2f5c7e4880b5cc70c87cc466ba7c3b96a36123c1","README.md":"2bde1fc990113ff261d65e107e4c2bda4de9337761a07b9d272959585f1e57cd","src/lib.rs":"ecb33d80c8351fd53dfbeee9f3456737db72d78f0f0fbbfc3603add76d8fdbb3"},"package":"ca3a870aefc42d175d11fb1ec089221ced8a160d66ca1e0c64a57b4ae90d2462"}

View File

@ -0,0 +1,16 @@
# Changelog
## Unreleased
- …
## fluent-pseudo 0.2.0 (December 13, 2019)
- Exclude access-keys and other single-char messages.
## fluent-pseudo 0.1.0 (November 26, 2019)
- 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.

View File

@ -13,9 +13,8 @@
[package]
edition = "2018"
name = "fluent-pseudo"
version = "0.2.3"
version = "0.2.1"
authors = ["Zibi Braniecki <gandalf@mozilla.com>", "Staś Małolepszy <stas@mozilla.com>"]
include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md"]
description = "Pseudolocalization transformation API for use with Project Fluent API.\n"
homepage = "http://www.projectfluent.org"
readme = "README.md"
@ -24,4 +23,4 @@ categories = ["localization", "internationalization"]
license = "Apache-2.0/MIT"
repository = "https://github.com/projectfluent/fluent-rs"
[dependencies.regex]
version = "1"
version = "1.3"

View File

@ -45,4 +45,4 @@ fn main() {
assert_eq!(&value, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!");
}
```
```

View File

@ -3,12 +3,12 @@ use regex::Regex;
use std::borrow::Cow;
static TRANSFORM_SMALL_MAP: &[char] = &[
'a', 'ƀ', 'ƈ', 'ḓ', 'e', 'ƒ', 'ɠ', 'ħ', 'i', 'ĵ', 'ķ', 'ŀ', 'ḿ', 'ƞ', 'o', 'ƥ', 'ɋ', 'ř', 'ş',
'ŧ', 'u', 'ṽ', 'ẇ', 'ẋ', 'ẏ', 'ẑ',
'ȧ', 'ƀ', 'ƈ', 'ḓ', '', 'ƒ', 'ɠ', 'ħ', 'ī', 'ĵ', 'ķ', 'ŀ', 'ḿ', 'ƞ', 'ǿ', 'ƥ', 'ɋ', 'ř', 'ş',
'ŧ', 'ŭ', 'ṽ', 'ẇ', 'ẋ', 'ẏ', 'ẑ',
];
static TRANSFORM_CAPS_MAP: &[char] = &[
'A', 'Ɓ', 'Ƈ', 'Ḓ', 'E', 'Ƒ', 'Ɠ', 'Ħ', 'I', 'Ĵ', 'Ķ', 'Ŀ', 'Ḿ', 'Ƞ', 'O', 'Ƥ', 'Ɋ', 'Ř', 'Ş',
'Ŧ', 'U', 'Ṽ', 'Ẇ', 'Ẋ', 'Ẏ', 'Ẑ',
'Ȧ', 'Ɓ', 'Ƈ', 'Ḓ', '', 'Ƒ', 'Ɠ', 'Ħ', 'Ī', 'Ĵ', 'Ķ', 'Ŀ', 'Ḿ', 'Ƞ', 'Ǿ', 'Ƥ', 'Ɋ', 'Ř', 'Ş',
'Ŧ', 'Ŭ', 'Ṽ', 'Ẇ', 'Ẋ', 'Ẏ', 'Ẑ',
];
static FLIPPED_SMALL_MAP: &[char] = &[
@ -20,9 +20,6 @@ static FLIPPED_CAPS_MAP: &[char] = &[
'⊥', '∩', 'Ʌ', 'M', 'X', '⅄', 'Z',
];
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> {
// Exclude access-keys and other single-char messages
if s.len() == 1 {
@ -30,8 +27,7 @@ pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
}
// XML entities (&#x202a;) and XML tags.
let re_excluded =
unsafe { RE_EXCLUDED.get_or_insert_with(|| Regex::new(r"&[#\w]+;|<\s*.+?\s*>").unwrap()) };
let re_excluded = Regex::new(r"&[#\w]+;|<\s*.+?\s*>").unwrap();
let mut result = Cow::from(s);
@ -55,12 +51,15 @@ pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
let range = pos..s.len();
let result_range = pos + diff..result.len();
let transform_sub = transform(&s[range], flipped, elongate);
result.to_mut().replace_range(result_range, &transform_sub);
result
.to_mut()
.replace_range(result_range, &transform_sub);
result
}
pub fn transform(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
let re_az = unsafe { RE_AZ.get_or_insert_with(|| Regex::new(r"[a-zA-Z]").unwrap()) };
// XXX: avoid recreating it on each call.
let re_az = Regex::new(r"[a-zA-Z]").unwrap();
let (small_map, caps_map) = if flipped {
(FLIPPED_SMALL_MAP, FLIPPED_CAPS_MAP)
@ -69,12 +68,11 @@ pub fn transform(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
};
re_az.replace_all(s, |caps: &Captures| {
let ch = caps[0].chars().next().unwrap();
let ch = caps[0].chars().nth(0).unwrap();
let cc = ch as u8;
if cc >= 97 && cc <= 122 {
let pos = cc - 97;
let new_char = small_map[pos as usize];
// duplicate "a", "e", "o" and "u" to emulate ~30% longer text
if elongate && (cc == 97 || cc == 101 || cc == 111 || cc == 117) {
let mut s = new_char.to_string();
s.push(new_char);
@ -99,10 +97,10 @@ mod tests {
#[test]
fn it_works() {
let x = transform("Hello World", false, true);
assert_eq!(x, "Ħeeŀŀoo Ẇoořŀḓ");
assert_eq!(x, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ");
let x = transform("Hello World", false, false);
assert_eq!(x, "Ħeŀŀo Ẇořŀḓ");
assert_eq!(x, "Ħḗŀŀǿ Ẇǿřŀḓ");
let x = transform("Hello World", true, false);
assert_eq!(x, "Hǝʅʅo Moɹʅp");
@ -114,10 +112,10 @@ mod tests {
#[test]
fn dom_test() {
let x = transform_dom("Hello <a>World</a>", false, true);
assert_eq!(x, "Ħeeŀŀoo <a>Ẇoořŀḓ</a>");
assert_eq!(x, "Ħḗḗŀŀǿǿ <a>Ẇǿǿřŀḓ</a>");
let x = transform_dom("Hello <a>World</a> in <b>my</b> House.", false, true);
assert_eq!(x, "Ħeeŀŀoo <a>Ẇoořŀḓ</a> iƞ <b>ḿẏ</b> Ħoouuşee.");
assert_eq!(x, "Ħḗḗŀŀǿǿ <a>Ẇǿǿřŀḓ</a> īƞ <b>ḿẏ</b> Ħǿǿŭŭşḗḗ.");
// Don't touch single character values.
let x = transform_dom("f", false, true);