Skip to content

Proper way to display ordinal numbers #359

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

Closed
Cimbali opened this issue Oct 7, 2023 · 3 comments
Closed

Proper way to display ordinal numbers #359

Cimbali opened this issue Oct 7, 2023 · 3 comments

Comments

@Cimbali
Copy link
Contributor

Cimbali commented Oct 7, 2023

The docs give the following example:

your-rank = { NUMBER($pos, type: "ordinal") ->
   [1] You finished first!
   [one] You finished {$pos}st
   [two] You finished {$pos}nd
   [few] You finished {$pos}rd
  *[other] You finished {$pos}th
}

But it seems type: "ordinal" is not recognised. Even when ignoring the CLDR plural categories and changing the selector for exact matches we are limited:

> cat en/test.ftl
your-rank = { $pos ->
   [1] You finished first!
   [2] You finished {$pos}nd
   [3] You finished {$pos}rd
  *[other] You finished {$pos}th
}
> python3 -c 'from fluent.runtime import FluentLocalization as Loc, FluentResourceLoader as Load
print(Loc(["en"], ["test.ftl"], Load("{locale}")).format_value("your-rank", {"pos": 21}))'
You finished 21th

So what is the option to properly display irregular ordinals (X1st, X2nd, X3rd)? Is there a number format for ordinals? Is there a way to perform a calculation on the selector (here $pos > 20 + $pos % 10 could do but this will be locale-specific)? Or is my only option to enumerate them all?

@eemeli
Copy link
Member

eemeli commented Oct 9, 2023

If the results are as you describe also with the example that's in the docs, then I believe you've found a bug with the Python implementation, rather than a spec bug.

@Cimbali
Copy link
Contributor Author

Cimbali commented Oct 10, 2023

Here’s what the python implementation does with the docs example:

> cat en/test.ftl 
your-rank = { NUMBER($pos, type: "ordinal") ->
   [1] You finished first!
   [one] You finished {$pos}st
   [two] You finished {$pos}nd
   [few] You finished {$pos}rd
  *[other] You finished {$pos}th
}
> test() {
python3 -c "from fluent.runtime import FluentLocalization as Loc, FluentResourceLoader as Load
print(Loc(['en'], ['test.ftl'], Load('{locale}')).format_value('your-rank', {'pos': $1}))"
}
> test 1
You finished 1th
> test 2
You finished 2th
> test 5
You finished 5th
> test 21
You finished 21th

I’ve just checked that the js implementation produces the expected strings first/2nd/5th/21st, so I’ll open a bug over on the python implementation.

@Cimbali Cimbali closed this as completed Oct 10, 2023
@Cimbali
Copy link
Contributor Author

Cimbali commented Oct 25, 2023

Follow-up at issue projectfluent/python-fluent#192 and PR projectfluent/python-fluent#193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants