At the moment PluralFormula doesn't filter or validate the input from a .po file.

If someone accidentally copies the .pot template to a .po file the Plural-Forms will be invalid:

"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

In turn this will cause a bug on the "User interface translation" overview:
User interface translation

Another side-effect will be that PluralFormula::loadFormulae stores the faulty plural definition "INTEGER" in a State variable:

$ drush state-get locale.translation.formulae
array(1) {
 ["locale.translation.formulae"]=>
 array(3) {
   ["nl"]=>
   array(2) {
     ["plurals"]=>
     string(7) "INTEGER"
     ["formula"]=>
     array(1) {
       ["default"]=>
       int(0)
     }
   }

In turn, this results in a bug where plurals no longer work because PluralTranslatableMarkup::getPluralIndex will always return the singular string:

Comments

mpp created an issue. See original summary.

mpp’s picture

Status: Active » Needs review
StatusFileSize
new843 bytes
mpp’s picture

Issue summary: View changes
andypost’s picture

+++ b/core/modules/locale/src/PluralFormula.php
@@ -74,8 +74,8 @@ public function getNumberOfPlurals($langcode = NULL) {
+    // We assume 2 plurals if there is no explicit information yet, or if the information is invalid.

needs wrap at 80 chars

mpp’s picture

StatusFileSize
new851 bytes

Wrapped the comment. Do we also wrap if() statements?

I should probably also use ctype_digit instead of is_int.

The last submitted patch, 2: 3005958_2.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 5: 3005958_5.patch, failed testing. View results

andypost’s picture

No reason to wrap "if" here
Meanwhile failed tests means this condition needs BC shim

mpp’s picture

Status: Needs work » Needs review
StatusFileSize
new852 bytes

Testing with ctype_digit as the number is probably formatted as a string.

mpp’s picture

Perhaps it would be better to throw an Exception if the plural information is invalid?

mpp’s picture

Issue summary: View changes
Priority: Normal » Major
StatusFileSize
new1.29 MB

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This will need a test case to show the issue.

Did not test for issue btw.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

gábor hojtsy’s picture

Title: Add input filter to PluralFormula » Invalid plural formula is not rejected
Issue tags: +Plural handling