Update dependencies

This commit is contained in:
Savanni D'Gerinel 2022-04-21 09:14:53 -04:00
parent 78ca4b6a09
commit 033e9982ea
3 changed files with 84 additions and 103 deletions

View File

@ -9,7 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc4d7142005e2066e4844caf9f271b93fc79836ee96ec85057b8c109687e629a" checksum = "bc4d7142005e2066e4844caf9f271b93fc79836ee96ec85057b8c109687e629a"
dependencies = [ dependencies = [
"fluent-bundle", "fluent-bundle",
"unic-langid 0.9.0", "unic-langid",
] ]
[[package]] [[package]]
@ -25,7 +25,7 @@ dependencies = [
"rustc-hash", "rustc-hash",
"self_cell", "self_cell",
"smallvec", "smallvec",
"unic-langid 0.9.0", "unic-langid",
] ]
[[package]] [[package]]
@ -34,7 +34,7 @@ version = "0.2.0"
dependencies = [ dependencies = [
"fluent", "fluent",
"fluent-syntax", "fluent-syntax",
"unic-langid 0.8.0", "unic-langid",
] ]
[[package]] [[package]]
@ -43,7 +43,7 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c4ad0989667548f06ccd0e306ed56b61bd4d35458d54df5ec7587c0e8ed5e94" checksum = "2c4ad0989667548f06ccd0e306ed56b61bd4d35458d54df5ec7587c0e8ed5e94"
dependencies = [ dependencies = [
"unic-langid 0.9.0", "unic-langid",
] ]
[[package]] [[package]]
@ -62,7 +62,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f" checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f"
dependencies = [ dependencies = [
"type-map", "type-map",
"unic-langid 0.9.0", "unic-langid",
] ]
[[package]] [[package]]
@ -72,7 +72,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf" checksum = "b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf"
dependencies = [ dependencies = [
"tinystr", "tinystr",
"unic-langid 0.9.0", "unic-langid",
] ]
[[package]] [[package]]
@ -157,31 +157,13 @@ dependencies = [
"rustc-hash", "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]] [[package]]
name = "unic-langid" name = "unic-langid"
version = "0.9.0" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73328fcd730a030bdb19ddf23e192187a6b01cd98be6d3140622a89129459ce5" checksum = "73328fcd730a030bdb19ddf23e192187a6b01cd98be6d3140622a89129459ce5"
dependencies = [ dependencies = [
"unic-langid-impl 0.9.0", "unic-langid-impl",
]
[[package]]
name = "unic-langid-impl"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c43c61e94492eb67f20facc7b025778a904de83d953d8fcb60dd9adfd6e2d0ea"
dependencies = [
"tinystr",
] ]
[[package]] [[package]]

View File

@ -19,5 +19,5 @@ include = [
[dependencies] [dependencies]
fluent = "0.15" fluent = "0.15"
unic-langid = "0.8" unic-langid = "0.9"
fluent-syntax = "0.11" fluent-syntax = "0.11"

View File

@ -3,8 +3,7 @@
//! The Fluent class makes it easier to load translation bundles with language fallbacks and to go //! 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. //! through the most common steps of translating a message.
//! //!
use fluent::FluentBundle; use fluent::{FluentArgs, FluentBundle, FluentError, FluentResource};
use fluent::{FluentArgs, FluentError, FluentResource};
use fluent_syntax::parser::ParserError; use fluent_syntax::parser::ParserError;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
@ -98,11 +97,11 @@ pub struct FluentErgo {
impl fmt::Debug for FluentErgo { impl fmt::Debug for FluentErgo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "FluentErgo") write!(f, "FluentErgo")
//write!( //write!(
//f, //f,
//"FluentErgo {{ language: {:?}, units: {} }}", //"FluentErgo {{ language: {:?}, units: {} }}",
//self.language, "whatever, for the moment" //self.language, "whatever, for the moment"
//) //)
} }
} }
@ -156,7 +155,7 @@ impl FluentErgo {
bundle.add_resource(res).map_err(|err| Error::from(err)) bundle.add_resource(res).map_err(|err| Error::from(err))
} }
Entry::Vacant(e) => { 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))?; bundle.add_resource(res).map_err(|err| Error::from(err))?;
e.insert(bundle); e.insert(bundle);
Ok(()) Ok(())
@ -234,7 +233,7 @@ impl FluentErgo {
let bundle = bundles.get(lang)?; let bundle = bundles.get(lang)?;
self.tr_(bundle, msgid, args) self.tr_(bundle, msgid, args)
}) })
.filter(|v| v.is_some()) .filter(|v| v.is_some())
.map(|v| v.unwrap()) .map(|v| v.unwrap())
.next(); .next();
@ -249,9 +248,9 @@ impl FluentErgo {
bundle: &FluentBundle<FluentResource>, bundle: &FluentBundle<FluentResource>,
msgid: &str, msgid: &str,
args: Option<&FluentArgs>, args: Option<&FluentArgs>,
) -> Option<String> { ) -> Option<String> {
let mut errors = vec![]; 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 { let res = match pattern {
None => None, None => None,
Some(p) => { Some(p) => {
@ -286,83 +285,83 @@ time_display = {$time} during the day
nested_display = nesting a time display: {time_display} nested_display = nesting a time display: {time_display}
"; ";
const EO_TRANSLATIONS: &'static str = " const EO_TRANSLATIONS: &'static str = "
history = Historio history = Historio
"; ";
#[test] #[test]
fn translations() { fn translations() {
let en_id = "en-US".parse::<LanguageIdentifier>().unwrap(); let en_id = "en-US".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]); let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS)) .add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load"); .expect("text should load");
assert_eq!( assert_eq!(
fluent.tr("preferences", None).unwrap(), fluent.tr("preferences", None).unwrap(),
String::from("Preferences") String::from("Preferences")
); );
} }
#[test] #[test]
fn translation_fallback() { fn translation_fallback() {
let eo_id = "eo".parse::<LanguageIdentifier>().unwrap(); let eo_id = "eo".parse::<LanguageIdentifier>().unwrap();
let en_id = "en".parse::<LanguageIdentifier>().unwrap(); let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![eo_id.clone(), en_id.clone()]); let mut fluent = FluentErgo::new(&vec![eo_id.clone(), en_id.clone()]);
fluent fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS)) .add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load"); .expect("text should load");
fluent fluent
.add_from_text(eo_id, String::from(EO_TRANSLATIONS)) .add_from_text(eo_id, String::from(EO_TRANSLATIONS))
.expect("text should load"); .expect("text should load");
assert_eq!( assert_eq!(
fluent.tr("preferences", None).unwrap(), fluent.tr("preferences", None).unwrap(),
String::from("Preferences") String::from("Preferences")
); );
assert_eq!( assert_eq!(
fluent.tr("history", None).unwrap(), fluent.tr("history", None).unwrap(),
String::from("Historio") String::from("Historio")
); );
} }
#[test] #[test]
fn placeholder_insertion_should_strip_placeholder_markers() { fn placeholder_insertion_should_strip_placeholder_markers() {
let en_id = "en".parse::<LanguageIdentifier>().unwrap(); let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]); let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS)) .add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load"); .expect("text should load");
let mut args = FluentArgs::new(); let mut args = FluentArgs::new();
args.insert("time", FluentValue::from(String::from("13:00"))); args.insert("time", FluentValue::from(String::from("13:00")));
assert_eq!( assert_eq!(
fluent.tr("time_display", Some(&args)).unwrap(), fluent.tr("time_display", Some(&args)).unwrap(),
String::from("13:00 during the day") String::from("13:00 during the day")
); );
} }
#[test] #[test]
fn placeholder_insertion_should_strip_nested_placeholder_markers() { fn placeholder_insertion_should_strip_nested_placeholder_markers() {
let en_id = "en".parse::<LanguageIdentifier>().unwrap(); let en_id = "en".parse::<LanguageIdentifier>().unwrap();
let mut fluent = FluentErgo::new(&vec![en_id.clone()]); let mut fluent = FluentErgo::new(&vec![en_id.clone()]);
fluent fluent
.add_from_text(en_id, String::from(EN_TRANSLATIONS)) .add_from_text(en_id, String::from(EN_TRANSLATIONS))
.expect("text should load"); .expect("text should load");
let mut args = FluentArgs::new(); let mut args = FluentArgs::new();
args.insert("time", FluentValue::from(String::from("13:00"))); args.insert("time", FluentValue::from(String::from("13:00")));
assert_eq!( assert_eq!(
fluent.tr("nested_display", Some(&args)).unwrap(), fluent.tr("nested_display", Some(&args)).unwrap(),
String::from("nesting a time display: 13:00 during the day") String::from("nesting a time display: 13:00 during the day")
); );
} }
#[test] #[test]
fn test_send() { fn test_send() {
fn assert_send<T: Send>() {} fn assert_send<T: Send>() {}
assert_send::<FluentErgo>(); assert_send::<FluentErgo>();
} }
#[test] #[test]
fn test_sync() { fn test_sync() {
fn assert_sync<T: Sync>() {} fn assert_sync<T: Sync>() {}
assert_sync::<FluentErgo>(); assert_sync::<FluentErgo>();
} }
} }