diff --git a/fluent-ergonomics/Cargo.lock b/fluent-ergonomics/Cargo.lock index 2ae6ae9..e785058 100644 --- a/fluent-ergonomics/Cargo.lock +++ b/fluent-ergonomics/Cargo.lock @@ -9,7 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc4d7142005e2066e4844caf9f271b93fc79836ee96ec85057b8c109687e629a" dependencies = [ "fluent-bundle", - "unic-langid 0.9.0", + "unic-langid", ] [[package]] @@ -25,7 +25,7 @@ dependencies = [ "rustc-hash", "self_cell", "smallvec", - "unic-langid 0.9.0", + "unic-langid", ] [[package]] @@ -34,7 +34,7 @@ version = "0.2.0" dependencies = [ "fluent", "fluent-syntax", - "unic-langid 0.8.0", + "unic-langid", ] [[package]] @@ -43,7 +43,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c4ad0989667548f06ccd0e306ed56b61bd4d35458d54df5ec7587c0e8ed5e94" dependencies = [ - "unic-langid 0.9.0", + "unic-langid", ] [[package]] @@ -62,7 +62,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f" dependencies = [ "type-map", - "unic-langid 0.9.0", + "unic-langid", ] [[package]] @@ -72,7 +72,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf" dependencies = [ "tinystr", - "unic-langid 0.9.0", + "unic-langid", ] [[package]] @@ -157,31 +157,13 @@ dependencies = [ "rustc-hash", ] -[[package]] -name = "unic-langid" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d81136159f779c35b10655f45210c71cd5ca5a45aadfe9840a61c7071735ed" -dependencies = [ - "unic-langid-impl 0.8.0", -] - [[package]] name = "unic-langid" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73328fcd730a030bdb19ddf23e192187a6b01cd98be6d3140622a89129459ce5" dependencies = [ - "unic-langid-impl 0.9.0", -] - -[[package]] -name = "unic-langid-impl" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43c61e94492eb67f20facc7b025778a904de83d953d8fcb60dd9adfd6e2d0ea" -dependencies = [ - "tinystr", + "unic-langid-impl", ] [[package]] diff --git a/fluent-ergonomics/Cargo.toml b/fluent-ergonomics/Cargo.toml index 6e9c0b2..ddf281b 100644 --- a/fluent-ergonomics/Cargo.toml +++ b/fluent-ergonomics/Cargo.toml @@ -19,5 +19,5 @@ include = [ [dependencies] fluent = "0.15" -unic-langid = "0.8" +unic-langid = "0.9" fluent-syntax = "0.11" diff --git a/fluent-ergonomics/src/lib.rs b/fluent-ergonomics/src/lib.rs index 9edd347..3426b6b 100644 --- a/fluent-ergonomics/src/lib.rs +++ b/fluent-ergonomics/src/lib.rs @@ -3,8 +3,7 @@ //! The Fluent class makes it easier to load translation bundles with language fallbacks and to go //! through the most common steps of translating a message. //! -use fluent::FluentBundle; -use fluent::{FluentArgs, FluentError, FluentResource}; +use fluent::{FluentArgs, FluentBundle, FluentError, FluentResource}; use fluent_syntax::parser::ParserError; use std::collections::hash_map::Entry; use std::collections::HashMap; @@ -98,11 +97,11 @@ pub struct FluentErgo { impl fmt::Debug for FluentErgo { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "FluentErgo") - //write!( - //f, - //"FluentErgo {{ language: {:?}, units: {} }}", - //self.language, "whatever, for the moment" - //) + //write!( + //f, + //"FluentErgo {{ language: {:?}, units: {} }}", + //self.language, "whatever, for the moment" + //) } } @@ -156,7 +155,7 @@ impl FluentErgo { bundle.add_resource(res).map_err(|err| Error::from(err)) } Entry::Vacant(e) => { - let mut bundle = FluentBundle::new(&[lang]); + let mut bundle = FluentBundle::new(vec![lang]); bundle.add_resource(res).map_err(|err| Error::from(err))?; e.insert(bundle); Ok(()) @@ -234,7 +233,7 @@ impl FluentErgo { let bundle = bundles.get(lang)?; self.tr_(bundle, msgid, args) }) - .filter(|v| v.is_some()) + .filter(|v| v.is_some()) .map(|v| v.unwrap()) .next(); @@ -249,9 +248,9 @@ impl FluentErgo { bundle: &FluentBundle, msgid: &str, args: Option<&FluentArgs>, - ) -> Option { + ) -> Option { let mut errors = vec![]; - let pattern = bundle.get_message(msgid).and_then(|msg| msg.value); + let pattern = bundle.get_message(msgid).and_then(|msg| msg.value()); let res = match pattern { None => None, Some(p) => { @@ -286,83 +285,83 @@ time_display = {$time} during the day nested_display = nesting a time display: {time_display} "; -const EO_TRANSLATIONS: &'static str = " + const EO_TRANSLATIONS: &'static str = " history = Historio "; -#[test] -fn translations() { - let en_id = "en-US".parse::().unwrap(); - let mut fluent = FluentErgo::new(&vec![en_id.clone()]); - fluent - .add_from_text(en_id, String::from(EN_TRANSLATIONS)) - .expect("text should load"); - assert_eq!( - fluent.tr("preferences", None).unwrap(), - String::from("Preferences") + #[test] + fn translations() { + let en_id = "en-US".parse::().unwrap(); + let mut fluent = FluentErgo::new(&vec![en_id.clone()]); + fluent + .add_from_text(en_id, String::from(EN_TRANSLATIONS)) + .expect("text should load"); + assert_eq!( + fluent.tr("preferences", None).unwrap(), + String::from("Preferences") ); -} + } -#[test] -fn translation_fallback() { - let eo_id = "eo".parse::().unwrap(); - let en_id = "en".parse::().unwrap(); - let mut fluent = FluentErgo::new(&vec![eo_id.clone(), en_id.clone()]); - fluent - .add_from_text(en_id, String::from(EN_TRANSLATIONS)) - .expect("text should load"); - fluent - .add_from_text(eo_id, String::from(EO_TRANSLATIONS)) - .expect("text should load"); - assert_eq!( - fluent.tr("preferences", None).unwrap(), - String::from("Preferences") + #[test] + fn translation_fallback() { + let eo_id = "eo".parse::().unwrap(); + let en_id = "en".parse::().unwrap(); + let mut fluent = FluentErgo::new(&vec![eo_id.clone(), en_id.clone()]); + fluent + .add_from_text(en_id, String::from(EN_TRANSLATIONS)) + .expect("text should load"); + fluent + .add_from_text(eo_id, String::from(EO_TRANSLATIONS)) + .expect("text should load"); + assert_eq!( + fluent.tr("preferences", None).unwrap(), + String::from("Preferences") ); - assert_eq!( - fluent.tr("history", None).unwrap(), - String::from("Historio") + assert_eq!( + fluent.tr("history", None).unwrap(), + String::from("Historio") ); -} + } -#[test] -fn placeholder_insertion_should_strip_placeholder_markers() { - let en_id = "en".parse::().unwrap(); - let mut fluent = FluentErgo::new(&vec![en_id.clone()]); - fluent - .add_from_text(en_id, String::from(EN_TRANSLATIONS)) - .expect("text should load"); - let mut args = FluentArgs::new(); - args.insert("time", FluentValue::from(String::from("13:00"))); - assert_eq!( - fluent.tr("time_display", Some(&args)).unwrap(), - String::from("13:00 during the day") + #[test] + fn placeholder_insertion_should_strip_placeholder_markers() { + let en_id = "en".parse::().unwrap(); + let mut fluent = FluentErgo::new(&vec![en_id.clone()]); + fluent + .add_from_text(en_id, String::from(EN_TRANSLATIONS)) + .expect("text should load"); + let mut args = FluentArgs::new(); + args.insert("time", FluentValue::from(String::from("13:00"))); + assert_eq!( + fluent.tr("time_display", Some(&args)).unwrap(), + String::from("13:00 during the day") ); -} + } -#[test] -fn placeholder_insertion_should_strip_nested_placeholder_markers() { - let en_id = "en".parse::().unwrap(); - let mut fluent = FluentErgo::new(&vec![en_id.clone()]); - fluent - .add_from_text(en_id, String::from(EN_TRANSLATIONS)) - .expect("text should load"); - let mut args = FluentArgs::new(); - args.insert("time", FluentValue::from(String::from("13:00"))); - assert_eq!( - fluent.tr("nested_display", Some(&args)).unwrap(), - String::from("nesting a time display: 13:00 during the day") + #[test] + fn placeholder_insertion_should_strip_nested_placeholder_markers() { + let en_id = "en".parse::().unwrap(); + let mut fluent = FluentErgo::new(&vec![en_id.clone()]); + fluent + .add_from_text(en_id, String::from(EN_TRANSLATIONS)) + .expect("text should load"); + let mut args = FluentArgs::new(); + args.insert("time", FluentValue::from(String::from("13:00"))); + assert_eq!( + fluent.tr("nested_display", Some(&args)).unwrap(), + String::from("nesting a time display: 13:00 during the day") ); -} + } -#[test] -fn test_send() { - fn assert_send() {} - assert_send::(); -} + #[test] + fn test_send() { + fn assert_send() {} + assert_send::(); + } -#[test] -fn test_sync() { - fn assert_sync() {} - assert_sync::(); -} + #[test] + fn test_sync() { + fn assert_sync() {} + assert_sync::(); + } }