JSON Fallback
Out of the box, Laravel doesn't allow fallback translations for JSON keys. For example, when you call __('Remember Me')
, you get Remember Me
instead of Se souvenir de moi
for French fallback language.
To install, run the console command:
composer require laravel-lang/json-fallback
After this, you need to add a link to the service provider in the providers
section of the config/app.php
settings file:
<?php
use Illuminate\Support\ServiceProvider;
use Illuminate\Translation\TranslationServiceProvider as BaseTranslationServiceProvider;
use LaravelLang\JsonFallback\TranslationServiceProvider as JsonTranslationServiceProvider;
return [
'providers' => ServiceProvider::defaultProviders()->merge([
// your service providers
])->replace([
BaseTranslationServiceProvider::class => JsonTranslationServiceProvider::class,
])->toArray(),
];
Now JSON keys will correctly output the value based on the selected localization.
Last modified: 19 December 2023