D
D
dominy2021-09-30 17:02:10
Internationalization and localization
dominy, 2021-09-30 17:02:10

How to declare custom PluralizationRule vue-i18n Vue3?

Hello, I have a rule for pluralization from https://kazupon.github.io/vue-i18n/guide/pluraliza...
But declaring it as

setup() {
    const { t, locale } = useI18n({
      pluralizationRules: {
        ru: function (choice, choicesLength) {
          if (choice === 0) {
            return 0;
          }

          const teen = choice > 10 && choice < 20;
          const endsWithOne = choice % 10 === 1;

          if (choicesLength < 4) {
            return !teen && endsWithOne ? 1 : 2;
          }
          if (!teen && endsWithOne) {
            return 1;
          }
          if (!teen && choice % 10 >= 2 && choice % 10 <= 4) {
            return 2;
          }

          return choicesLength < 4 ? 2 : 3;
        },
      },
    });
    return { t, locale };
  },
It doesn't change anything (that is, by 0 - seconds, 1 - second, and the rest seconds) - how can I fix this ?
I need
...1 second
...2-...3-...4 seconds
.. .0-...5-...6-...7-...8-...9 seconds

<i18n>
{
  "en": {
    "seconds":"{count} seconds | {count} second | {count} seconds"
  },
  "ru":{
    "seconds":"{count} секунд | {count} секунда | {count} секунд"
  }
}
</i18n>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Levchenko, 2021-10-03
@nuykon

"ru":{
    "seconds":"{count} секунд | {count} секунда | {count} секунд"
  }

so you have only three cases described here, but there should be four:
return 0 | return 1 | return 2 | return 3
0 | 1,21,31... | 2-4, 22-24... | 5-20, 25-30...
"ru":{
    "seconds":"ноль секунд | одна секунда | {n} секунды | {n} секунд"
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question