From f21de9830675e7f70da9e5bbe62ba13b31c58bbe Mon Sep 17 00:00:00 2001 From: Craig Cornelius Date: Wed, 21 Aug 2024 15:43:19 -0700 Subject: [PATCH] ICU4X rel date time - non-Latn number system --> unsupported (#289) * ICU4X relative date time - label non-Latn numbering system as unsupported * Better setting of unicode extension in locale --- .../rust/1.3/src/relativedatetime_fmt.rs | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/executors/rust/1.3/src/relativedatetime_fmt.rs b/executors/rust/1.3/src/relativedatetime_fmt.rs index d609e908..61a8fcd9 100644 --- a/executors/rust/1.3/src/relativedatetime_fmt.rs +++ b/executors/rust/1.3/src/relativedatetime_fmt.rs @@ -1,7 +1,14 @@ // https://docs.rs/icu/1.3.2/icu/relativetime/struct.RelativeTimeFormatter.html +// https://docs.rs/icu_provider/1.3.0/icu_provider/struct.DataLocale.html#method.get_unicode_ext use fixed_decimal::FixedDecimal; + +use icu::locid::extensions::unicode; +use icu::locid::extensions::unicode::key; use icu::locid::Locale; + +use std::str::FromStr; + use icu_provider::DataLocale; use icu::relativetime::options::Numeric; @@ -128,16 +135,13 @@ pub fn run_relativedatetimeformat_test(json_obj: &Value) -> Result = &option_struct.numbering_system; + // Set up the locale with its options. let locale_json_str: &str = json_obj["locale"].as_str().unwrap(); - let mut locale_str: String = locale_json_str.to_string(); - if numbering_system_str.is_some() { - locale_str = - locale_json_str.to_string() + "-u-nu-" + &numbering_system_str.as_ref().unwrap(); - } + let locale_str: String = locale_json_str.to_string(); - let lang_id = if let Ok(lc) = locale_str.parse::() { + let locale_id = if let Ok(lc) = locale_str.parse::() { lc } else { return Ok(json!({ @@ -146,7 +150,31 @@ pub fn run_relativedatetimeformat_test(json_obj: &Value) -> Result