JSON Fallback | Laravel Lang

Laravel Lang Help

JSON Fallback

Installation

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

Usage

After installing, 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.

Compatibility

Laravel

PHP

Package

Status

10, 11

8.1, 8.2, 8.3

^2.0

supported

6, 7, 8, 9, 10

7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3

^1.0

not supported

Last modified: 06 June 2024