Skip to content

Commit 0c56e64

Browse files
committed
Switch to use ICU4X
1 parent a2cef6b commit 0c56e64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+176
-130
lines changed

Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"fluent-syntax",
45
"fluent-bundle",
@@ -16,16 +17,17 @@ exclude = [
1617

1718
[workspace.dependencies]
1819
criterion = "0.3"
19-
fluent-langneg = "0.13"
20+
fluent-langneg = "0.14"
2021
futures = "0.3"
2122
iai = "0.1"
22-
intl_pluralrules = "7.0.1"
2323
rustc-hash = "1"
2424
serde = "1.0"
2525
serde_json = "1.0"
2626
thiserror = "1.0"
2727
tokio = "1.0"
28-
unic-langid = "0.9"
28+
icu_locid = "1.4"
29+
icu_plurals = { version = "1.4", features = ["experimental"] }
30+
icu_provider = "1.4"
2931

3032
fluent-bundle = { path = "fluent-bundle" }
3133
fluent-fallback = { path = "fluent-fallback" }

fluent-bundle/Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ include = [
2626
]
2727

2828
[dependencies]
29-
fluent-langneg.workspace = true
29+
fluent-langneg = "0.14"
3030
fluent-syntax.workspace = true
31-
intl_pluralrules.workspace = true
3231
rustc-hash.workspace = true
33-
unic-langid.workspace = true
32+
icu_locid.workspace = true
33+
icu_plurals.workspace = true
34+
icu_provider.workspace = true
35+
fixed_decimal = { version = "0.5.5", features = ["ryu"] }
3436
intl-memoizer = { path = "../intl-memoizer" }
3537
self_cell = "0.10"
3638
smallvec = "1"
@@ -39,12 +41,12 @@ smallvec = "1"
3941
criterion.workspace = true
4042
iai.workspace = true
4143
serde = { workspace = true, features = ["derive"]}
42-
unic-langid = { workspace = true, features = ["macros"] }
4344
rand = "0.8"
4445
serde_yaml = "0.8"
4546

4647
[features]
47-
default = []
48+
default = ["icu_provider/sync"]
49+
sync = ["icu_provider/sync"]
4850
all-benchmarks = []
4951

5052
[[bench]]

fluent-bundle/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Usage
2323

2424
```rust
2525
use fluent_bundle::{FluentBundle, FluentResource};
26-
use unic_langid::langid;
26+
use icu_locid::langid;
2727

2828
fn main() {
2929
let ftl_string = "hello-world = Hello, world!".to_owned();

fluent-bundle/benches/resolver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::rc::Rc;
1010

1111
use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};
1212
use fluent_syntax::ast;
13-
use unic_langid::langid;
13+
use icu_locid::langid;
1414

1515
fn read_file(path: &str) -> Result<String, io::Error> {
1616
let mut f = File::open(path)?;

fluent-bundle/benches/resolver_iai.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};
22
use fluent_syntax::ast;
3-
use unic_langid::{langid, LanguageIdentifier};
3+
use icu_locid::{langid, LanguageIdentifier};
44

55
const LANG_EN: LanguageIdentifier = langid!("en");
66

fluent-bundle/examples/custom_formatter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// to format selected types of values.
33
//
44
// This allows users to plug their own number formatter to Fluent.
5-
use unic_langid::LanguageIdentifier;
5+
use icu_locid::LanguageIdentifier;
66

77
use fluent_bundle::memoizer::MemoizerKind;
88
use fluent_bundle::types::{FluentNumber, FluentNumberOptions};

fluent-bundle/examples/custom_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Lastly, we'll also create a new formatter which will be memoizable.
1010
//
1111
// The type and its options are modelled after ECMA402 Intl.DateTimeFormat.
12+
use icu_locid::LanguageIdentifier;
1213
use intl_memoizer::Memoizable;
13-
use unic_langid::LanguageIdentifier;
1414

1515
use fluent_bundle::types::FluentType;
1616
use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};

fluent-bundle/examples/external_arguments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};
2-
use unic_langid::langid;
2+
use icu_locid::langid;
33

44
fn main() {
55
let ftl_string = String::from(

fluent-bundle/examples/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use fluent_bundle::{FluentBundle, FluentResource, FluentValue};
2-
use unic_langid::langid;
2+
use icu_locid::langid;
33

44
fn main() {
55
// We define the resources here so that they outlive

fluent-bundle/examples/simple-app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
//! default one.
2020
use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};
2121
use fluent_langneg::{negotiate_languages, NegotiationStrategy};
22+
use icu_locid::{langid, LanguageIdentifier};
2223
use std::env;
2324
use std::fs;
2425
use std::fs::File;
2526
use std::io;
2627
use std::io::prelude::*;
2728
use std::path::Path;
2829
use std::str::FromStr;
29-
use unic_langid::{langid, LanguageIdentifier};
3030

3131
/// We need a generic file read helper function to
3232
/// read the localization resource file.

fluent-bundle/src/bundle.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::default::Default;
1212
use std::fmt;
1313

1414
use fluent_syntax::ast;
15+
use icu_locid::LanguageIdentifier;
1516
use intl_memoizer::IntlLangMemoizer;
16-
use unic_langid::LanguageIdentifier;
1717

1818
use crate::args::FluentArgs;
1919
use crate::entry::Entry;
@@ -32,7 +32,7 @@ use crate::types::FluentValue;
3232
///
3333
/// ```
3434
/// use fluent_bundle::{FluentBundle, FluentResource, FluentValue, FluentArgs};
35-
/// use unic_langid::langid;
35+
/// use icu_locid::langid;
3636
///
3737
/// // 1. Create a FluentResource
3838
///
@@ -163,7 +163,7 @@ impl<R, M> FluentBundle<R, M> {
163163
///
164164
/// ```
165165
/// use fluent_bundle::{FluentBundle, FluentResource};
166-
/// use unic_langid::langid;
166+
/// use icu_locid::langid;
167167
///
168168
/// let ftl_string = String::from("
169169
/// hello = Hi!
@@ -253,7 +253,7 @@ impl<R, M> FluentBundle<R, M> {
253253
///
254254
/// ```
255255
/// use fluent_bundle::{FluentBundle, FluentResource};
256-
/// use unic_langid::langid;
256+
/// use icu_locid::langid;
257257
///
258258
/// let ftl_string = String::from("
259259
/// hello = Hi!
@@ -359,7 +359,7 @@ impl<R, M> FluentBundle<R, M> {
359359
///
360360
/// ```
361361
/// use fluent_bundle::{FluentBundle, FluentResource};
362-
/// use unic_langid::langid;
362+
/// use icu_locid::langid;
363363
///
364364
/// let ftl_string = String::from("hello = Hi!");
365365
/// let resource = FluentResource::try_new(ftl_string)
@@ -384,7 +384,7 @@ impl<R, M> FluentBundle<R, M> {
384384
///
385385
/// ```
386386
/// use fluent_bundle::{FluentBundle, FluentResource};
387-
/// use unic_langid::langid;
387+
/// use icu_locid::langid;
388388
///
389389
/// let ftl_string = String::from("hello-world = Hello World!");
390390
/// let resource = FluentResource::try_new(ftl_string)
@@ -412,7 +412,7 @@ impl<R, M> FluentBundle<R, M> {
412412
///
413413
/// ```
414414
/// use fluent_bundle::{FluentBundle, FluentResource};
415-
/// use unic_langid::langid;
415+
/// use icu_locid::langid;
416416
///
417417
/// let ftl_string = String::from("hello-world = Hello World!");
418418
/// let resource = FluentResource::try_new(ftl_string)
@@ -459,7 +459,7 @@ impl<R, M> FluentBundle<R, M> {
459459
///
460460
/// ```
461461
/// use fluent_bundle::{FluentBundle, FluentResource};
462-
/// use unic_langid::langid;
462+
/// use icu_locid::langid;
463463
///
464464
/// let ftl_string = String::from("hello-world = Hello World!");
465465
/// let resource = FluentResource::try_new(ftl_string)
@@ -508,7 +508,7 @@ impl<R, M> FluentBundle<R, M> {
508508
///
509509
/// ```
510510
/// use fluent_bundle::{FluentBundle, FluentResource, FluentValue};
511-
/// use unic_langid::langid;
511+
/// use icu_locid::langid;
512512
///
513513
/// let ftl_string = String::from("length = { STRLEN(\"12345\") }");
514514
/// let resource = FluentResource::try_new(ftl_string)
@@ -567,7 +567,7 @@ impl<R> FluentBundle<R, IntlLangMemoizer> {
567567
/// ```
568568
/// use fluent_bundle::FluentBundle;
569569
/// use fluent_bundle::FluentResource;
570-
/// use unic_langid::langid;
570+
/// use icu_locid::langid;
571571
///
572572
/// let langid_en = langid!("en-US");
573573
/// let mut bundle: FluentBundle<FluentResource> = FluentBundle::new(vec![langid_en]);

fluent-bundle/src/concurrent.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use icu_locid::LanguageIdentifier;
12
use intl_memoizer::{concurrent::IntlLangMemoizer, Memoizable};
23
use rustc_hash::FxHashMap;
3-
use unic_langid::LanguageIdentifier;
44

55
use crate::memoizer::MemoizerKind;
66
use crate::types::FluentType;
@@ -23,7 +23,7 @@ impl<R> FluentBundle<R> {
2323
/// ```
2424
/// use fluent_bundle::concurrent::FluentBundle;
2525
/// use fluent_bundle::FluentResource;
26-
/// use unic_langid::langid;
26+
/// use icu_locid::langid;
2727
///
2828
/// let langid_en = langid!("en-US");
2929
/// let mut bundle: FluentBundle<FluentResource> =

fluent-bundle/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum FluentError {
3333
///
3434
/// ```
3535
/// use fluent_bundle::{FluentBundle, FluentResource};
36-
/// use unic_langid::langid;
36+
/// use icu_locid::langid;
3737
///
3838
/// let ftl_string = String::from("intro = Welcome, { $name }.");
3939
/// let res1 = FluentResource::try_new(ftl_string)

fluent-bundle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! ```
1919
//! use fluent_bundle::{FluentBundle, FluentValue, FluentResource, FluentArgs};
2020
//! // Used to provide a locale for the bundle.
21-
//! use unic_langid::langid;
21+
//! use icu_locid::langid;
2222
//!
2323
//! // 1. Crate a FluentResource
2424
//!

fluent-bundle/src/memoizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::types::FluentType;
2+
use icu_locid::LanguageIdentifier;
23
use intl_memoizer::Memoizable;
3-
use unic_langid::LanguageIdentifier;
44

55
/// This trait contains thread-safe methods which extend [intl_memoizer::IntlLangMemoizer].
66
/// It is used as the generic bound in this crate when a memoizer is needed.

fluent-bundle/src/types/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::borrow::{Borrow, Cow};
2222
use std::fmt;
2323
use std::str::FromStr;
2424

25-
use intl_pluralrules::{PluralCategory, PluralRuleType};
25+
use icu_plurals::{PluralCategory, PluralRuleType};
2626

2727
use crate::memoizer::MemoizerKind;
2828
use crate::resolver::Scope;
@@ -157,10 +157,10 @@ impl<'source> FluentValue<'source> {
157157
/// ```
158158
/// use fluent_bundle::resolver::Scope;
159159
/// use fluent_bundle::{types::FluentValue, FluentBundle, FluentResource};
160-
/// use unic_langid::langid;
160+
/// use icu_locid::langid;
161161
///
162-
/// let langid_ars = langid!("en");
163-
/// let bundle: FluentBundle<FluentResource> = FluentBundle::new(vec![langid_ars]);
162+
/// let langid_en = langid!("en");
163+
/// let bundle: FluentBundle<FluentResource> = FluentBundle::new(vec![langid_en]);
164164
/// let scope = Scope::new(&bundle, None, None);
165165
///
166166
/// // Matching examples:
@@ -189,12 +189,12 @@ impl<'source> FluentValue<'source> {
189189
(&FluentValue::Number(ref a), &FluentValue::Number(ref b)) => a == b,
190190
(&FluentValue::String(ref a), &FluentValue::Number(ref b)) => {
191191
let cat = match a.as_ref() {
192-
"zero" => PluralCategory::ZERO,
193-
"one" => PluralCategory::ONE,
194-
"two" => PluralCategory::TWO,
195-
"few" => PluralCategory::FEW,
196-
"many" => PluralCategory::MANY,
197-
"other" => PluralCategory::OTHER,
192+
"zero" => PluralCategory::Zero,
193+
"one" => PluralCategory::One,
194+
"two" => PluralCategory::Two,
195+
"few" => PluralCategory::Few,
196+
"many" => PluralCategory::Many,
197+
"other" => PluralCategory::Other,
198198
_ => return false,
199199
};
200200
// This string matches a plural rule keyword. Check if the number
@@ -203,8 +203,8 @@ impl<'source> FluentValue<'source> {
203203
.bundle
204204
.intls
205205
.with_try_get_threadsafe::<PluralRules, _, _>(
206-
(PluralRuleType::CARDINAL,),
207-
|pr| pr.0.select(b) == Ok(cat),
206+
(PluralRuleType::Cardinal,),
207+
|pr| pr.0.category_for(b) == cat,
208208
)
209209
.unwrap()
210210
}

fluent-bundle/src/types/number.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::borrow::Cow;
2-
use std::convert::TryInto;
32
use std::default::Default;
43
use std::str::FromStr;
54

6-
use intl_pluralrules::operands::PluralOperands;
5+
use icu_plurals::PluralOperands;
76

87
use crate::args::FluentArgs;
98
use crate::types::FluentValue;
@@ -219,18 +218,12 @@ macro_rules! from_num {
219218

220219
impl From<&FluentNumber> for PluralOperands {
221220
fn from(input: &FluentNumber) -> Self {
222-
let mut operands: Self = input
223-
.value
224-
.try_into()
225-
.expect("Failed to generate operands out of FluentNumber");
221+
use fixed_decimal::{FixedDecimal, FloatPrecision};
222+
let mut fd = FixedDecimal::try_from_f64(input.value, FloatPrecision::Floating).unwrap();
226223
if let Some(mfd) = input.options.minimum_fraction_digits {
227-
if mfd > operands.v {
228-
operands.f *= 10_u64.pow(mfd as u32 - operands.v as u32);
229-
operands.v = mfd;
230-
}
224+
fd.pad_end(-(mfd as i16));
231225
}
232-
// XXX: Add support for other options.
233-
operands
226+
(&fd).into()
234227
}
235228
}
236229

fluent-bundle/src/types/plural.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
use fluent_langneg::{negotiate_languages, NegotiationStrategy};
1+
use icu_locid::LanguageIdentifier;
2+
use icu_plurals::{PluralRuleType, PluralRules as IntlPluralRules};
23
use intl_memoizer::Memoizable;
3-
use intl_pluralrules::{PluralRuleType, PluralRules as IntlPluralRules};
4-
use unic_langid::LanguageIdentifier;
54

65
pub struct PluralRules(pub IntlPluralRules);
76

87
impl Memoizable for PluralRules {
98
type Args = (PluralRuleType,);
109
type Error = &'static str;
1110
fn construct(lang: LanguageIdentifier, args: Self::Args) -> Result<Self, Self::Error> {
12-
let default_lang: LanguageIdentifier = "en".parse().unwrap();
13-
let pr_lang = negotiate_languages(
14-
&[lang],
15-
&IntlPluralRules::get_locales(args.0),
16-
Some(&default_lang),
17-
NegotiationStrategy::Lookup,
18-
)[0]
19-
.clone();
20-
Ok(Self(IntlPluralRules::create(pr_lang, args.0)?))
11+
let inner = match args.0 {
12+
PluralRuleType::Cardinal => IntlPluralRules::try_new_cardinal(&lang.into()),
13+
PluralRuleType::Ordinal => IntlPluralRules::try_new_ordinal(&lang.into()),
14+
_ => todo!(),
15+
};
16+
Ok(Self(inner.unwrap()))
2117
}
2218
}

fluent-bundle/tests/bundle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use fluent_bundle::{FluentArgs, FluentBundle, FluentResource};
2+
use icu_locid::langid;
23
use std::borrow::Cow;
3-
use unic_langid::langid;
44

55
#[test]
66
fn add_resource_override() {

0 commit comments

Comments
 (0)