Problem/Motivation

\Drupal\l10n_packager\L10nExporter::export() exports PO files with an invalid plural formula, so they cannot be imported.

Steps to reproduce

Export a PO file and attempt to import it on a different Drupal site. The importer will choke on the plural formula.

Proposed resolution

Fix the exported plural formula. Also remove a bunch of unnecessary (and incorrect?) quoting from the resulting PO file.

Remaining tasks

User interface changes

-

API changes

-

Data model changes

-

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

tstoeckler created an issue. See original summary.

tstoeckler’s picture

Status: Active » Needs review

See #3541994: Fix CI for the CI failures.

With this I am properly able to import the exported PO file on a different Drupal site.

teebeecoder’s picture

Status: Needs review » Needs work

Hi @tstoeckler,

Thanks for your work on this MR 🙏
We won’t be merging the changes as they are right now, since they modify how the .po file is generated, which could introduce unintended side effects.

Could you please update the MR to include only the changes related to plural handling and remove the rest?

Thanks!

cc @FMB

tstoeckler’s picture

Hey there, absolutely no problem. Thanks of taking a look, regardless. Just wanted to send a heads-up that I'm not sure when I will get to this. Will leave this on my todo list for now, and hope to get to it soon-ish, but cannot guarantee anything, we'll see.

gábor hojtsy’s picture

Looked at this again while comparing the packager with the Drupal 7 version for the localize.drupal.org upgrade.

The root cause is that l10n_packager carries its own copy of the exporter, an older fork of the l10n_community one. Its plural header takes the l10n_pconfig formula setting, which already holds the whole nplurals=2; plural=(n!=1); string, and wraps it again into nplurals=2; plural=nplurals=2; plural=(n!=1);;. The l10n_community exporter had the plural header commented out with a todo, so its files have no Plural-Forms line at all. In Drupal 7 the packager calls l10n_community_export(), there is one exporter.

The change I landed does the same on 3.0.x: the packager uses the l10n_community.exporter service and its own copy is removed. The community exporter now writes Plural-Forms from the l10n_pconfig formula of the language, and the nplurals=INTEGER; plural=EXPRESSION; placeholder for templates without a language, like Drupal 7. The \n escapes in the header lines stay, they are part of the PO format, so the quoting cleanup from the merge request is left out as asked in #4.

Tests: the Drupal 7 export and packager tests assert the plural header first, the ported L10nExportTest and PackagerFilePerLanguageTest assert the same. Kernel tests enabling l10n_packager now also enable l10n_community, which l10n_packager depends on.

LLM was used to find, diagnose explain and fix this issue. With human review.

  • 0eb1e629 committed on 7.x-1.x
    fix #3543340: \Drupal\l10n_packager\L10nExporter::export() is broken...

  • 5529d373 committed on 3.0.x
    fix #3543340: \Drupal\l10n_packager\L10nExporter::export() is broken...
gábor hojtsy’s picture

Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.