Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Do not trigger missing translation key handling when checking existence of translation key #52895

Conversation

gdebrauwer
Copy link
Contributor

Since #52343, the missing translation key handling is triggered when using the trans_choice method with a translation key that has no translation in the app's current locale but does have a translation in the fallback locale.

// Translation key: "foo.bar"
// Translation in English (en): ":count Foo|:count Bar"
// Translation in Dutch (nl): Not set!
// Fallback Locale is English

app()->setLocale('en');
trans_choice('foo.bar', 1);
// --> Does not trigger "Lang::handleMissingKeysUsing" closure which is correct

app()->setLocale('nl');
trans_choice('foo.bar', 1);
// --> Triggers "Lang::handleMissingKeysUsing" closure which is not correct
//     because a translation in the fallback locale (= 'en') does exist!

This is caused by the fact that it checks the existence of a translation key without a fallback to the fallback locale. To fix this, I changed the has method of the Translator class so that checking the existence of a key does not trigger the Lang::handleMissingKeysUsing closure.

@taylorotwell taylorotwell merged commit f8f0668 into laravel:11.x Sep 24, 2024
32 checks passed
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