Skip to main content
Version: Legacy

JSON Fallback

Stable unknown

View on GitHub

warning

If you use English as a fallback localization, then you do not need to use this package.

Installation​

note

The compatibility table can be viewed here.

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:^2.3.0

Usage​

note

In Laravel 11, the providers section is missing from the config/app.php configuration file. You can add it manually.

After installing, you need to add a link to the service provider in the providers section of the config/app.php settings file:

<?php

declare(strict_types=1);

use Illuminate\Support\ServiceProvider;
use Illuminate\Translation\TranslationServiceProvider as BaseTranslation;
use LaravelLang\JsonFallback\TranslationServiceProvider as JsonTranslation;

return [
'providers' => ServiceProvider::defaultProviders()->merge([
// other service providers
])->replace([
BaseTranslation::class => JsonTranslation::class,
])->toArray(),
];

Now JSON keys will correctly output the value based on the selected localization.

Compatibility​

LaravelPHPPackageStatus
10, 11, 12, 138.1, 8.2, 8.3, 8.4, 8.5^2.0supported
6, 7, 8, 9, 107.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3^1.0not supported