projectfluent / python-fluent

Python implementation of Project Fluent
https://projectfluent.org/python-fluent/
Other
210 stars 26 forks source link

Ordinals do not work #192

Closed Cimbali closed 7 months ago

Cimbali commented 1 year ago

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
}

Checking via the online editor I see we get the following strings:

1: You finished first!
2: You finished 2nd
3: You finished 3rd
4: You finished 4th
5: You finished 5th
…
20: You finished 20th
21: You finished 21st
22: You finished 22nd
23: You finished 23rd
24: You finished 24rd
25: You finished 25rd

But the python implementation seems to not recognise the type: "ordinal" on the selector and we always get the “other” case:

>>> from fluent.runtime import FluentLocalization, FluentResourceLoader
>>> l10n = FluentLocalization(['en'], ['test.ftl'], FluentResourceLoader('{locale}'))
>>> l10n.format_value('your-rank', {'pos': 1})
'You finished 1th'
>>> l10n.format_value('your-rank', {'pos': 2})
'You finished 2th'
>>> l10n.format_value('your-rank', {'pos': 3})
'You finished 3th'
>>> l10n.format_value('your-rank', {'pos': 5})
'You finished 5th'
>>> l10n.format_value('your-rank', {'pos': 21})
'You finished 21th'
>>> l10n.format_value('your-rank', {'pos': 22})
'You finished 22th'
>>> l10n.format_value('your-rank', {'pos': 23})
'You finished 23th'