Plural form format

I just started translating and I can’t find any documentation on how the plural form format works.

Example string: All the places have been taken|One place is still available|{places} places are still available

My language’s plural rules

In an nutshell, I need to have multiple versions of the {places} places are still available depending on which number it is being fetched for.

Unfortunately for now we’re stuck with this library to handle front-end translations which has poor build-in support for pluralization, so it needs custom rules for languages.

If you are interested, I can help giving a hand with building the custom pluralization rules for your language, as we’ll only be able to move to something else in the long term.

Thanks for the info! This rule should do it (untested):

    /**
     * Plural Groups for gd locale:
     * - 1, 11
     * - 2, 12
     * - anything else > 2 && < 20
     * - 0, 20+
     * @param choice {number} a choice index given by the input to $tc: `$tc('path.to.rule', choiceIndex)`
     * @param choicesLength {number} an overall amount of available choices
     * @returns a final choice index to select plural word by
     */
    'gd': function(choice, choicesLength) {
      // this === VueI18n instance, so the locale property also exists here

      if (choice === 1 || choice === 11) {
        return 0;
      }

      if (choice === 2 || choice === 12) {
        return 1;
      }

      return (choice > 0 && choice < 20) ? 2 : 3;
    }

In the example I have above, there is special handling for 0 and 1. We now have 2 choices - make an unusual plural rule, or split the string?

I’m not sure what you mean. You refer to the fact the string is translated as All the places have been taken instead of something like 0 place is still available

I’ve merged this rule and it seems to work properly.

¹ Also this string is a bad example, it shouldn’t have been pluralizable in the first place.

Thanks for implementing the rule :slight_smile:

Yes, it’s definitely a bad example. Do you want me to flag strings like this one up with source string comments on Weblate as I go along?

Yes, I’ve just configured Weblate to notify me of those.

I have searched for | and marked them all up.

Most of the pural uses contain a special case for 0 and 1 - maybe it would be less work to modify the plural rule with a special case for 0 and 1 after all? I’m simply skipping these strings for now until we have a final decision.