Skip to content

Allow checking plural strings with Translator::exists() - #67

Merged
williamdes merged 1 commit into
phpmyadmin:masterfrom
anyingiit:exists-plural
Oct 23, 2026
Merged

williamdes merged 1 commit into
phpmyadmin:masterfrom
anyingiit:exists-plural

Conversation

@anyingiit

Copy link
Copy Markdown

Description

Translator::exists() only looks up the key it is given, but a string with plural forms is stored under its singular and plural msgids joined by a NUL byte (the key ngettext() builds). So, as reported in #59, exists('event') is false for an entry with msgid "event" / msgid_plural "event+", and there was no way to check such an entry at all.

This adds an optional second parameter, mirroring ngettext():

$translator->exists('event', 'event+'); // true

Existing calls are unaffected (exists('event') keeps its meaning and still returns false for a plural-only entry, since the lookup by singular alone would need a scan of the cache, which ApcuCache cannot do cheaply). The docblock says how plural entries are checked. A new MoFilesTest::testExistsWithPlural runs over every .mo fixture, like testExists.

I did not add a CHANGELOG entry since entries there reference the PR number — happy to add one once the PR exists, and to retarget 5.4.x / 6.0.x if you'd rather ship this as a fix there.

Motivation / disclosure: I had some spare AI-assistant quota (Claude Code) and am using it to try to help projects with open good-first-issues / help-wanted issues. The change was prepared with Claude Code and verified as listed below. If it doesn't fit, isn't up to your bar, or you'd simply rather not take it — please feel free to close it, no hard feelings at all 🙂

Related issue

Fixes #59

Checklist

  • Tests pass locally — vendor/bin/phpunit → 127 tests OK (21 skipped: the APCu tests, no APCu here). Without the change the 6 new data sets fail. vendor/bin/phpcs on the changed files is clean; PHPStan reports the same output as on master (I ran it without the phpstan extensions installed).
  • CHANGELOG.md is updated — see above.
  • Documentation is updated — the method docblock.

A string with plural forms is stored under its singular and plural
msgids joined by a NUL byte, so exists() could never find it by the
singular msgid alone. Add an optional plural msgid parameter that builds
the same key as ngettext().

Fixes phpmyadmin#59

Signed-off-by: anyingiit <49945850+anyingiit@users.noreply.github.com>
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.33%. Comparing base (7536000) to head (506220f).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #67      +/-   ##
============================================
- Coverage     98.94%   94.33%   -4.62%     
- Complexity      108      109       +1     
============================================
  Files             8        8              
  Lines           284      300      +16     
============================================
+ Hits            281      283       +2     
- Misses            3       17      +14     
Flag Coverage Δ
unit-8.2 98.95% <100.00%> (+<0.01%) ⬆️
unit-8.3 98.95% <100.00%> (+<0.01%) ⬆️
unit-8.4 94.33% <100.00%> (-4.62%) ⬇️
unit-8.5 94.33% <100.00%> (-4.62%) ⬇️
unit-8.6 94.33% <100.00%> (-4.62%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@williamdes williamdes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the code looks good and the logic acceptable.
Due to the hard to do concat I think it is best we have a second argument

@williamdes williamdes self-assigned this Oct 23, 2026
@williamdes williamdes added this to the 6.0.0 milestone Oct 23, 2026
@williamdes
williamdes removed the request for review from MauricioFauth October 23, 2026 11:49
@williamdes williamdes modified the milestones: 6.0.0, 6.0.2 Oct 23, 2026
@williamdes
williamdes merged commit 6de8db1 into phpmyadmin:master Oct 23, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Translator exists method fails on plurals

2 participants