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:setupdate 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:exportwritenplurals=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 thenplurals=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:
- #2882617: String version of plural formula is not available, exported .po files contain an incorrect default, and its duplicate #2882667: [PP-1] Interface translations export contains incorrect plural formula: the module stores the plural formula of each language, and the exports write it into the Plural-Forms header.
- #2918489: Plurals are not exported correctly when exporting source translations: each plural string gets a msgstr line for each plural form, and templates get 2.
- #3005958: Invalid plural formula is not rejected: the language form validates the plural formula, and an imported file with an invalid plural formula does not change the language's plural formula.
- #3207627: Empty plural formula is not validated in imported .po file: an imported file without a Plural-Forms header does not change the language's plural formula.
- #3631998: Overwrite protection lost for plural formulas due to dead code: the module keeps the plural formula, unless the import overwrites translations or the language does not have a plural formula yet.
- #2499639: Use correct labels for numeric fields when using a multiple plural forms language: the module labels each plural variant field with the numbers of its plural form.
- #3632104: Configuration translation saves a delimiter-only string when all plural variants are empty, instead of dropping it: the configuration translation form removes a plural translation with all its variants empty, in place of saving the delimiters only. It also removes a plural translation that is only the source variants followed by empty variants: for a language with more plural forms than the source, the form has these values for every untranslated plural.
It also works around these Drush issues:
drush locale:exportwrites the Plural-Forms header and the msgstr lines of core, like the export form (#2882617: String version of plural formula is not available, exported .po files contain an incorrect default and #2918489: Plurals are not exported correctly when exporting source translations). With the module, the output has the plural formula of the language and a msgstr line for each plural form, with Drush 12, 13 and 14.- drush-ops/drush#6630: locale:export --template fails with a TypeError, on Drush 13.8 and 14: the command passes the language code
NULLof a template to a method with astringargument. With the module, templates work.
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
- Project categories: Multilingual
34 sites report using this module
- Created by gábor hojtsy on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Plural debugging tools, UI improvements to Drupal and import and export .po fixes for known unfixed core issues




