diff --git a/fluent-bundle/src/types/mod.rs b/fluent-bundle/src/types/mod.rs index 6729a8b9..d5e5663e 100644 --- a/fluent-bundle/src/types/mod.rs +++ b/fluent-bundle/src/types/mod.rs @@ -131,13 +131,16 @@ impl<'source> FluentValue<'source> { "other" => PluralCategory::OTHER, _ => return false, }; + let kind = match b.options.kind { + FluentNumberKind::Cardinal => PluralRuleType::CARDINAL, + FluentNumberKind::Ordinal => PluralRuleType::ORDINAL, + }; scope .bundle .intls - .with_try_get_threadsafe::( - (PluralRuleType::CARDINAL,), - |pr| pr.0.select(b) == Ok(cat), - ) + .with_try_get_threadsafe::((kind,), |pr| { + pr.0.select(b) == Ok(cat) + }) .unwrap() } _ => false, diff --git a/fluent-bundle/src/types/number.rs b/fluent-bundle/src/types/number.rs index d39291ff..e3947dfc 100644 --- a/fluent-bundle/src/types/number.rs +++ b/fluent-bundle/src/types/number.rs @@ -8,6 +8,28 @@ use intl_pluralrules::operands::PluralOperands; use crate::args::FluentArgs; use crate::types::FluentValue; +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum FluentNumberKind { + Cardinal, + Ordinal, +} + +impl std::default::Default for FluentNumberKind { + fn default() -> Self { + Self::Cardinal + } +} + +impl From<&str> for FluentNumberKind { + fn from(input: &str) -> Self { + match input { + "cardinal" => Self::Cardinal, + "ordinal" => Self::Ordinal, + _ => Self::default(), + } + } +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum FluentNumberStyle { Decimal, @@ -58,6 +80,7 @@ impl From<&str> for FluentNumberCurrencyDisplayStyle { #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct FluentNumberOptions { + pub kind: FluentNumberKind, pub style: FluentNumberStyle, pub currency: Option, pub currency_display: FluentNumberCurrencyDisplayStyle, @@ -72,6 +95,7 @@ pub struct FluentNumberOptions { impl Default for FluentNumberOptions { fn default() -> Self { Self { + kind: Default::default(), style: Default::default(), currency: None, currency_display: Default::default(),