Repository navigation
Allow checking plural strings with Translator::exists() - #67
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
williamdes
approved these changes
Oct 23, 2026
williamdes
left a comment
Member
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 keyngettext()builds). So, as reported in #59,exists('event')isfalsefor an entry withmsgid "event"/msgid_plural "event+", and there was no way to check such an entry at all.This adds an optional second parameter, mirroring
ngettext():Existing calls are unaffected (
exists('event')keeps its meaning and still returnsfalsefor a plural-only entry, since the lookup by singular alone would need a scan of the cache, whichApcuCachecannot do cheaply). The docblock says how plural entries are checked. A newMoFilesTest::testExistsWithPluralruns over every.mofixture, liketestExists.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.xif 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
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/phpcson the changed files is clean; PHPStan reports the same output as onmaster(I ran it without the phpstan extensions installed).CHANGELOG.mdis updated — see above.