If a po file with a header without the plural forms specified is imported it can destroy plural handling of a language

Created on 7 April 2021, about 4 years ago
Updated 3 February 2023, about 2 years ago

Problem/Motivation

When importing a file without the plural header, but having a language with a correct plural header, you can destroy the plural handling for the language in question, since it's set after importing a file to the database, and when no plural header can be found it uses the default one in the constructor, which is nplurals=2; plural=(n > 1);

Steps to reproduce

- Enable one language (for example Norwegian).
- Import translations (should happen automatically).
- Print a plural formatted string. For example this:

new \Drupal\Core\StringTranslation\PluralTranslatableMarkup(0, 'one thing', '@count things'),

In Norwegian that should print "several things".

- Import the following file (example) without a plural formula header:

msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2021-02-25 09:15+0100\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Last-Translator: NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "A giant game of chess they play"
msgstr "De spiller et kjempestort sjakkparti"

View the same string. It will now be wrong.

Of course, I just know it will be wrong, since I know the plural form of my language, Norwegian, but this should apply to all languages that does not have the "default" formula nplurals=2; plural=(n > 1);

Proposed resolution

I see 2 resolutions:
- If a language already has a formula, do not overwrite it all of the time. I assume changing the plural forms of a language is not done in the same frequency as a person importing translations on a site. In fact, I would say such a change is actually not something you want to introduce automatically like this, even if it was changed overnight for a language.

or

- If a file does not have a plural formula, reset the default one, so it does not overwrite the existing one with just a (seemingly, for the user, random) default one.

Remaining tasks

Decide on it, and write a patch

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

n/a

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Language systemΒ  β†’

Last updated 4 days ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡³πŸ‡΄Norway eiriksm Norway

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    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.

    Did not test MR but will need a test case showing the issue please.

    Also if MR could be updated to 10.1 please.

  • Status changed to Postponed: needs info 5 days ago
  • πŸ‡«πŸ‡·France luukyb

    Hi @eiriksm,
    Could you provide more information about the file and why it would not include the plurals forms in the header? The way I understand the documentation is that if your language does not follow the default pluralization forms of words (singular: 1, anything else including 0 is plural), then it's a requirement for your file to include the line telling about the plural forms in the header. It's a requirement.

    If your language does not follow the same pluralization scheme as English, your PO file will need to contain a line telling about the plural forms in the header, in this format: Plural-Forms: nplurals=1; plural=0;

    See: https://www.drupal.org/community/contributor-guide/reference-information/localize-drupal-org/working-with-offline/po-and-pot-files#s-plural-forms β†’

    Thanks!

  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

    @luukyb: it is a requirement yeah but Drupal should be more graceful when this happens and not overwrite the plural handling?

Production build 0.71.5 2024