grammyjs / i18n

Internationalization for grammY powered by Fluent.
https://grammy.dev/plugins/i18n
MIT License
31 stars 6 forks source link

Ordinal numbers plural selector are not working #44

Closed 8549 closed 1 month ago

8549 commented 11 months ago

The third example on the Fluent docs page "Selectors" does not work with grammY's i18n plugin.

MWE

# en.ftl
request-success = You are { NUMBER($queueLength, type:"ordinal") ->
  [1] next
  [one] the {$queueLength}st
  [two] the {$queueLength}nd
  [few] the {$queueLength}rd
  *[other] the {$queueLength}th
} in queue!
// main.ts
import { load } from "dotenv";
import { Bot, Context } from "grammy";
import { I18n, I18nFlavor } from "@grammyjs/i18n";

const env = await load();

const i18n = new I18n({
  defaultLocale: "it",
  directory: "locales",
});

const bot = new Bot<Context & I18nFlavor>(env["BOT_TOKEN"]);
bot.use(i18n);
bot.command(
  "example",
  (ctx) => ctx.reply(ctx.t("request-success", { queueLength: 2 })),
);
bot.start();

Expected result

Bot replies with "You are 2nd in queue!"

Actual result

Bot replies with "Your are 2th in queue!" Same result if queueLength = 3.

dcdunkan commented 4 months ago

I'm so sorry for responding to this so late. You probably have moved on with this already. But if you are still interested or if anyone else comes around wondering about this:

Here is the same snippet from the "Selectors" page (https://projectfluent.org/fluent/guide/selectors.html):

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
}

running in their own playground (link):

screenshot

As you can see, it also returns "2th" instead of "2nd". As far as I know, the playground uses the latest versions of fluent packages.

So I ended up investigating more and found out that there is no such option in Number formatting. I believe that the docs wasn't updated correctly. You can't find the "type" option among the available option for Number formatting: https://projectfluent.org/fluent/guide/functions.html#number.

However, I tried looking through Python and Rust implementations of fluent, and saw some code that is responsible for ordinal and cardinal "type" argument. No such argument is allowed in the JavaScript (npm) package though. This seems to be a bug/missing feature in the JS package, and not i18n, which doesn't mess with the arguments at all.

I don't have more information. I'll try to look into raising an issue in the fluent repository and asking about this. Thanks for the report, although this is like 7 months old.

KnorpelSenf commented 1 month ago

Closing due to inactivity