Skip to content

Keep plural translations when merging with a template - #318

Merged
oscarotero merged 1 commit into
php-gettext:masterfrom
jayhemnani9910:fix-merge-keep-plural-translations
Nov 30, 2026
Merged

oscarotero merged 1 commit into
php-gettext:masterfrom
jayhemnani9910:fix-merge-keep-plural-translations

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Merging a .pot loaded with PoLoader into an existing PO with the default strategy drops the PO's plural translations:

$pot = (new PoLoader())->loadFile('messages.pot'); // msgstr[0] "" / msgstr[1] ""
$po = (new PoLoader())->loadFile('fr.po');         // msgstr[1] "%d fichiers"
$pot->mergeWith($po)->find(null, '%d file')->getPluralTranslations(); // ['']

The template's empty msgstr[1] is read as [''], which empty() treats as a value, so the merge keeps it. The singular translation comes through because it is checked with hasValue(). Plural translations now count as set only when one of them has a value, on both sides of the check.

Added testMergeKeepsPluralTranslationsOverEmptyTemplate; it fails on master. The full suite passes.

A .pot read by PoLoader has msgstr[n] "", so its pluralTranslations is
[''], which empty() treats as set, and merging it with a PO dropped the
PO's plural translations.
@oscarotero
oscarotero merged commit 7ead774 into php-gettext:master Nov 30, 2026
11 checks passed
@oscarotero

Copy link
Copy Markdown
Member

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants