Problem/Motivation

TranslationManager::selectPluralForm() and Drupal.formatPlural() use different logic so pick different variants:

Language Count Variant index picked by PHP Variant index picked by JavaScript
Javanese (n != 0) 1 🔴 0 🟢 1
Russian 201 🟢 0 🔴 2
Polish 202 🟢 1 🔴 2
Polish, untranslated 5 🟢 1 🔴 undefined
Any language, missing variant 1 2 🟢 0 🔴 undefined
Any language, empty variant 1 2 🔴 empty 🔴 empty
French (n > 1) 1.5 🟢 0 🔴 1
No formula "1" 🟢 0 🔴 1
  • PHP returns variant 0 for 1 without the formula (was #3496223: Plural Formula gets ignored for Singular Case for languages where Singular Form is not found in the first index, closed as duplicate to solve this more complete here).
  • The formula table has 0 to 199. Above 199, PHP uses 100 + n % 100, JavaScript the default entry, which is quite wrong.
  • For missing variants (can happen due to translation inconsistencies), PHP returns variant 1, or 0 for one variant, JavaScript undefined.
  • Both return empty text as-is for empty variants, which the translation form saves for empty fields where the translator did not provide the variant.
  • For non-integer numbers, PHP uses the integer part, like gettext, JavaScript uses the default entry instead.
  • Without a formula, JavaScript uses count !== 1, PHP also allows count "1", the comparison is not strict.

Proposed resolution

Unify how the logic works between the two programming languages, of course picking the correct decision in each case.

Add tests for all of these cases for both PHP and JS.

LLM disclosure

Generated with the help of an LLM.

Issue fork drupal-3631950

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gábor hojtsy created an issue. See original summary.

gábor hojtsy’s picture

Issue summary: View changes
gábor hojtsy’s picture

Status: Active » Needs review
gábor hojtsy’s picture

Issue summary: View changes

Simplify table to make it easier to see where is wrong :)

gábor hojtsy’s picture

Issue summary: View changes