Custom language editing with plural formula field
Suggested plural formulas search dialog
Plural status checker to find and resolve issues
Custom plural labels on interface translation and configuration translation

Drupal knows how many plural variants each language has and which one to use for a number, but it only learns this from imported .po files, and it has no user interface to configure it. Drupal core does not even store the original formula, only a computed lookup table. Plural forms adds the plural formula to the add and edit forms of languages, with the plural formulae of all the languages of localize.drupal.org as defaults. It keeps the formula and Drupal's computed lookup in sync, checks the plural translations of each language, labels each plural variant field with its numbers, and checks the variants when they are saved.

Features

  • Defaults from Drupal's translations: the plural formulae of all the languages of localize.drupal.org, which are the same as in the translation files. A predefined language gets its plural formula automatically when you add it.
  • Suggestions, also for regional language variants: the language form shows the suggested plural formula of the language code, like the one of German (de) for de-AT, with a "Use this value" button.
  • A searchable list of the plural formulae: with the plural forms of each formula, like "Form for numbers ending with 2–4, but not with 12–14", and a "Choose formula" button that copies a plural formula into the field.
  • Validation with clear messages: the format of the Plural-Forms header, the number of plural forms, the plural expression and the range of its plural forms.
  • Plural formulae in sync: an imported .po file sets the language's plural formula, when the import overwrites translations or the language does not have a formula yet. Saving a language, a configuration import and drush config:set update Drupal's computed lookup. On a site with languages, the installation sets a plural formula for each language without one, from its language code or from Drupal's computed lookup.
  • Plural status checks: a "Plural status" tab on the language list shows for each language whether Drupal's computed lookup matches the plural formula, and whether each plural interface translation and each plural configuration string has a variant, which is not empty, for each plural form. When the source has @count, each variant for more than one number should have it too: in French, the first variant is for 0 and 1. A page for each language lists the issues, with links to fix them. The status report has the number of languages with plural problems.
  • Labels with the numbers of each plural form: the interface translation form, the configuration translation form and the "Format plural" settings of Views numeric fields label each variant field like "Form for 1", "Form for numbers ending with 1, but not with 11" or "Form for other numbers", in place of "Singular form" and "2. plural form". When the source has @count, a variant field for more than one number has the description "Use @count for the number."
  • Checks when saving plural variants: the same forms show an error on an empty variant, and on a variant for more than one number without @count, when the source has @count. Emptying all the variants of a translation still removes the translation. The "Format plural" settings of Views have no source: when a variant has @count, each variant for more than one number should have it, and no variant can be empty.
  • Right plural formulae in exported files: core's interface translation export and drush locale:export write nplurals=2; plural=(n > 1); into every file, whatever the language. With this module, the file gets the plural formula of the language, each plural string gets a msgstr line for each plural form, and templates get the nplurals=INTEGER; plural=EXPRESSION; placeholder. The Drush part works with Drush 12, 13 and 14.
  • An API for other modules: the plural formula of a language, the default plural formula of a language code, the validation of plural formulae, and the labels of a language's plural forms with the plural forms for more than one number. Localization server and Translation template extractor use the plural formulae.

Core and Drush issues the module works around until resolved there

Some of the module's features are workarounds for core and (transitively) Drush issues:

It also works around these Drush issues:

Permissions

The plural formula is on the language form and the plural status tab is on the language list, so the "Administer languages" permission controls them. Give that permission only to people who know the plural rules of the languages: with a wrong plural formula, translations show the wrong plural forms.

Former name

The module was formerly called Plural Formula Configurator, but it took on a lot more, so it was renamed to honor that, while the machine name was kept.

Project information

Releases