Skip to content

Commit

Permalink
Merge pull request #158 from robertbastian/main
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim authored Nov 1, 2023
2 parents 67ce061 + 7003e64 commit 1616b72
Show file tree
Hide file tree
Showing 83 changed files with 128 additions and 2,597 deletions.
2,529 changes: 123 additions & 2,406 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions crates/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,11 @@ license = "MIT OR Apache-2.0"
[features]
default = []
proto = ["dep:prost", "dep:prost-build"]
icu = ["dep:icu_plurals", "dep:icu_datagen", "dep:icu_provider_adapters"]

[[bin]]
name = "generate_proto"
required-features = ["proto"]


[[bin]]
name = "generate_icu"
required-features = ["icu"]

[dependencies]
prost = { version = "0.11", optional = true }
prost-build = { version = "0.11", optional = true }

icu_plurals = { version = "1", features = ["std"], optional = true }
icu_datagen = { version = "1", optional = true }
icu_provider_adapters = { version = "1", features = ["std"], optional = true }


37 changes: 0 additions & 37 deletions crates/codegen/src/bin/generate_icu.rs

This file was deleted.

7 changes: 2 additions & 5 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ yarn_slinger_core = { path = "../core" }
unicode-normalization = "0.1"
unicode-segmentation = "1"
log = "0.4"
icu_plurals = { version = "1", features = ["std"] }
icu_locid = { version = "1", features = ["std"] }
icu_provider = { version = "1", features = ["std"] }
icu_provider_adapters = { version = "1", features = ["std"] }
icu_plurals = { version = "1.3", features = ["std"] }
icu_locid = { version = "1.3", features = ["std"] }
fixed_decimal = { version = "0.5", features = ["ryu", "std"] }
zerovec = { version = "0.9", features = ["std"] }
once_cell = "1"
regex = "1"
thiserror = "1"
Expand Down
37 changes: 3 additions & 34 deletions crates/runtime/src/pluralization.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use crate::pluralization::generated::generate_provider;
use crate::prelude::Language;
use fixed_decimal::{DoublePrecision, FixedDecimal};
use icu_locid::Locale;
use icu_plurals::{PluralCategory, PluralRuleType};
use icu_plurals::{PluralOperands, PluralRules};
use icu_provider::DataLocale;

mod generated;

#[derive(Debug)]
pub(crate) struct Pluralization {
Expand All @@ -17,8 +12,9 @@ pub(crate) struct Pluralization {
impl Pluralization {
pub(crate) fn new(language: impl Into<Language>) -> Self {
let language = language.into();
let locale: Locale = language.0.into();
let (cardinal_rules, ordinal_rules) = construct_cardinal_and_ordinal_rules(&locale);
let locale = language.0.into();
let cardinal_rules = PluralRules::try_new(&locale, PluralRuleType::Cardinal).unwrap();
let ordinal_rules = PluralRules::try_new(&locale, PluralRuleType::Ordinal).unwrap();
Self {
cardinal_rules,
ordinal_rules,
Expand All @@ -36,18 +32,6 @@ impl Pluralization {
}
}

fn construct_cardinal_and_ordinal_rules(
locale: impl Into<DataLocale>,
) -> (PluralRules, PluralRules) {
let provider = generate_provider();
let locale = locale.into();
let cardinal_rules =
PluralRules::try_new_unstable(&provider, &locale, PluralRuleType::Cardinal).unwrap();
let ordinal_rules =
PluralRules::try_new_unstable(&provider, &locale, PluralRuleType::Ordinal).unwrap();
(cardinal_rules, ordinal_rules)
}

fn get_into_plural_operand(value: f32) -> PluralOperands {
let rounded = value.round();
let floating_point = (rounded - value).abs();
Expand All @@ -63,7 +47,6 @@ mod tests {
//! Adapted from `TestNumberPlurals` in <https://github.com/YarnSpinnerTool/YarnSpinner/blob/da39c7195107d8211f21c263e4084f773b84eaff/YarnSpinner.Tests/LanguageTests.cs>
use super::*;
use icu_locid::locale;

#[test]
fn test_number_plurals() {
Expand Down Expand Up @@ -143,18 +126,4 @@ mod tests {
);
}
}

#[test]
fn smoke_test() {
let provider = generate_provider();
let pr = PluralRules::try_new_unstable(
&provider,
&locale!("en").into(),
PluralRuleType::Cardinal,
)
.expect("Failed to construct a PluralRules struct.");

assert_eq!(PluralCategory::One, pr.category_for(1_usize));
assert_eq!(PluralCategory::Other, pr.category_for(5_usize));
}
}
14 changes: 0 additions & 14 deletions crates/runtime/src/pluralization/generated.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/runtime/src/pluralization/icu/any.rs

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions crates/runtime/src/pluralization/icu/fallback/mod.rs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1616b72

Please sign in to comment.