You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I have stumbled across a small bug. Would like someone to confirm before I try creating a pull request to fix the problem.
Lang::handleMissingKeysUsing() is useful for logging missed translation keys. The third parameter of this callback is supposed to be the locale that is missing the translation. In some cases the $locale parameter is the config('app.fallback_locale') value instead of the current App::getLocale() value.
use Illuminate\Support\Facades\Lang;
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Lang::handleMissingKeysUsing(function (string $key, array $replacements, string $locale) {
dd($locale);
});
}
In your config/app.php file, 'locale' => 'en' and 'fallback_locale' => 'en'.
In your routes/web.php:
Route::get('test', function() {
app()->setLocale('fr');
__('does not exist');
});
If the key does not exist in both fr and en then the $locale parameter of the Lang::handleMissingKeysUsing() function will be en. I would expect it to be fr.
This kind of makes sense if you are using "short keys". In that case, you should have a translation in your fallback_locale. But if you are using JSON file translation approach there is no need for a fallback locale.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I think I have stumbled across a small bug. Would like someone to confirm before I try creating a pull request to fix the problem.
Lang::handleMissingKeysUsing()
is useful for logging missed translation keys. The third parameter of this callback is supposed to be the locale that is missing the translation. In some cases the$locale
parameter is theconfig('app.fallback_locale')
value instead of the currentApp::getLocale()
value.https://laravel.com/docs/10.x/localization#handling-missing-translation-strings
Steps to reproduce:
In your
config/app.php
file,'locale' => 'en'
and'fallback_locale' => 'en'
.In your
routes/web.php
:If the key does not exist in both
fr
anden
then the$locale
parameter of theLang::handleMissingKeysUsing()
function will been
. I would expect it to befr
.This kind of makes sense if you are using "short keys". In that case, you should have a translation in your
fallback_locale
. But if you are using JSON file translation approach there is no need for a fallback locale.Beta Was this translation helpful? Give feedback.
All reactions