Did you know that Drupal only learns how many plural variants a language has from imported .po files? It has a very fast lookup table to pick the right variant each time, but there is no UI to set or fix the rules. Get them wrong and your carefully translated strings fall back to the wrong form. Export your translations and the right plural rules don't come along either. I had a small module that provided a little bit of the solution since 2010 but recently decided to think bigger. The new version 3.1.0 of l10n_pconfig, released yesterday, is a huge update and it's tested with Drupal 10, 11 and 12. Read on to see all the new things!
A new name: Plural Forms Manager
The module started in 2010 as Plural Formula Configurator. Back then, editing the formula was the whole point. Now it does a lot more: it sets formulas for you, validates them, improves translation user interfaces, checks translations and fixes import and export. So it is now called Plural Forms Manager. The machine name stays l10n_pconfig of course, so nothing changes for existing sites.
Formulas just show up when you install
The module already knew the plural formulas from the languages of localize.drupal.org for predefined languages. Now, when you install it on a site that already has languages, it uses this information to set formulas for your existing languages. No more visiting each language one by one to get started. (The existing feature of automatically setting the proper plural formula when you add one from the predefined languages in Drupal is also still available).
Searchable formula browser
While there are a huge number of languages already automatically recognised, If you add a custom language that is not yet known by the module, a popup helps pick the plural formula you need based on real life examples.
Regional variants are understood
Language codes with subtags get a sensible suggestion too. Austrian German (de-AT) suggests the German (de) formula, for example. If you have regional variants of languages, you no longer start from scratch either.
Import and export that get it right
- Since your site remembers the plural formula with the module, exported .po files contain the language's correct plural formula in their header.
- When you import a .po file, its plural formula is saved to the language (when in overwrite mode).
- Translation templates get the right number of
msgstrlines for plural strings. - Drush 12, 13 and 14 translation exports also receive all these features (which needed dedicated integration code).
A friendlier translate UI
Plural variant fields in Interface Translation, Configuration Translation and even numeric views fields used to be labeled vaguely, which is confusing for languages with three, four or six forms. Each field is now labeled with the numbers it covers, like "Form for numbers ending with 1, but not with 11" instead of the incorrect "Singular form" core normally uses. If you forget a variant or the count placeholder, you get an error when saving, instead of a half-done or inaccurate translation.
A comprehensive plural health check
Last but not least, a new Plural status tab on the language list shows how each language is doing in terms of plural features. It flags mismatches between the formula and your translations, as well as empty plural variants and missing count placeholders. This helps fix issues that accumulated before you installed the module. The same information shows up on the status report, leading you to the detailed diagnosis UI.
Most should be improved directly in Drupal core
A contributed module working around core limitations is better than living with them, but the real goal is that every Drupal site gets a better plural experience. Many of these fixes originate from core issues that are still open, some of them for a long time. Each one has seen people put real time and thought into it, which I built on while implementing the module.
Now is a good time to review these core issues
On the core side, existing issues that are ready to review include .po import overwriting existing plural translations with empty text. Working on this version also turned up bugs nobody had reported yet. Core loses its overwrite protection for plural formulas on import and Configuration Translation saves just the delimiter when every plural variant is left empty, while Drush's locale:export --template crashes with a TypeError.
Two related issues the module doesn't solve are also ready for review: the need for count placeholders in singular text, so the right data shows up for untranslated scenarios, and PHP and JavaScript code not agreeing which plural variant to pick for the same number.
Issues for later that need more work before review
More existing issues resolved by the module that still need to be brought up to speed aim to store the formula as a string so exported .po files get the right default, export plurals correctly in source-only templates, reject invalid and empty formulas on import, and label plural fields by the numbers they cover.
Thanks to a lot of people
Thanks to everyone who worked on these over the years (in alphabetical order): alexpott, andypost, d34dman, darvanen, dww, eiriksm, hedrickbt, hestenet, hmdnawaz, idebr, jhodgdon, kunalgautam, larowlan, luukyb, Mark_L6n, maxocub, mglaman, mpp, niklan, penyaskito, qrinaldi, quietone, robincs, samiullah, smustgrave, Sutharsan, Tessa Bakker and xjm. On the new ones, penyaskito already reviewed the overwrite protection fix, and bercedev wrote the Drush fix the day after it was reported, with weitzman already reviewing it. If you could pick some of these up and help bring them over the finish line, that would be great!
Who would have guessed there's that much to discover about your plurals? Install the module, check your Plural status tab and feel free to share what you find in the issue queue. See you there!