Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options for cardinal/ordinal plural types #259

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions fluent-bundle/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<PluralRules, _, _>(
(PluralRuleType::CARDINAL,),
|pr| pr.0.select(b) == Ok(cat),
)
.with_try_get_threadsafe::<PluralRules, _, _>((kind,), |pr| {
pr.0.select(b) == Ok(cat)
})
.unwrap()
}
_ => false,
Expand Down
24 changes: 24 additions & 0 deletions fluent-bundle/src/types/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Please add docs here, with a link to the relevant Fluent documentation, and an example of what the .ftl syntax looks like.

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,
Expand Down Expand Up @@ -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<String>,
pub currency_display: FluentNumberCurrencyDisplayStyle,
Expand All @@ -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(),
Expand Down