[6.x] Adjust translation method usage#14610
Merged
jasonvarga merged 6 commits into6.xfrom May 6, 2026
Merged
Conversation
Adds 'use function Statamic\trans as __' to all PHP and Blade files that use __() for translations, preventing a lang-file/title collision (see issue #14609). Also adds a CI check script to enforce this going forward. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ll sites Adds a Statamic\trans_choice helper mirroring Statamic\trans (returning the key when the lookup resolves to an array), then imports trans/ trans_choice in files that call them directly without the __() alias. The CI check script now also enforces these imports. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This reverts commit e141308.
Covers the happy-path translation/pluralization and the array-collision fallback (returning the key when the lookup resolves to an array). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
What & Why
Fixes a lang-file/title collision where a translation key resolving to an array (e.g. a lang-file group whose name collides with a string key) caused incorrect output. Statamic's
Statamic\trans()wrapper detects this case and falls back to returning the key, but only if call sites actually route through the wrapper — Laravel's globaltrans(),__(), andtrans_choice()do not have this protection.This has happened many times in the past. We've fixed the specifically reported locations, but this keeps popping up, so this PR addresses it.
#2341, #4852, #6326, #7672, #14609
#5144, #6331, #9525
Changes
Helpers
Statamic\trans_choice()namespaced helper (andStatamic::transChoice()static method) that mirrors the existingStatamic\trans()— returning the key when the lookup resolves to an array, otherwise delegating to Laravel'strans_choice()for normal pluralization.Call-site imports
use function Statamic\trans as __;to every file using__()(240 files) — routes the alias through Statamic's wrapper.use function Statamic\trans;to files callingtrans()directly without the alias.use function Statamic\trans_choice;to files callingtrans_choice()directly.PHP's
use functionrebinds unqualified calls at compile time, so no call-site rewrites were needed — just imports.CI enforcement
scripts/check-trans-import.shwhich scanssrc/**/*.phpandresources/views/**/*.blade.phpfor unqualified__(),trans(), andtrans_choice()calls and fails if the correspondinguse function Statamic\…import is missing..github/workflows/code-style-lint.ymlto run on every push.Tests
Statamic::transandStatamic::transChoicecovering the happy path and the array-collision fallback.Closes #14609