Skip to content

Proper way to display ordinal numbers #359

@Cimbali

Description

@Cimbali

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions