Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291667

Plural Formula gets ignored for Singular Case for languages where Singular Form is not found in the first index

$
0
0

Problem/Motivation

Plural formula handling in PluralTranslatableMarkup::render() function ignores the Plural Formula Rule and hardcode the case for $count == 1 to use first index.

https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

As you can see from the latest code, It is ignoring the getPluralIndex for case where count is 1.

     $index = $this->getPluralIndex();
    if ($this->count == 1 || $index == 0 || count($translated_array) == 1) {
      // Singular form.
      $return = $translated_array[0];
    }

This leads to a problem where Plural Form Rules for languages where case for "count = 1" uses any other index but 0, leads to wrong Plural Form shown to user.

Example,

I was testing Plural Formula for Arabic, where singular form has index 1.

"Plural-Forms: nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5);\n

Steps to reproduce

- On Standard Drupal installation enable locale module
- Add and enable "Arabic" language
- Upload a Arabic PO file with translation for "@count items", this way you can set the rules for Arabic.
- Update Plural Translation for "1 comment" by visiting Translation edit for "/admin/config/regional/translate" to something as follows,

Notice that the labels provided for translators are already wrong here, since the first item is pointing to form for "zero" and second item points to "Singular" form.
- Run following code to display translation for singular form in Arabic,

ddev drush eval "print_r(\Drupal::translation()->formatPlural(1, '1 comment', '@count comments', array(), array('langcode' => 'ar')) . PHP_EOL);"

Result
1 - zero
Expected Result
1 - one

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

TBD

Introduced terminology

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD


Viewing all articles
Browse latest Browse all 291667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>