Laravel Lang Help

Installation

You can install the package via Composer:

composer require --dev laravel-lang/common

Now you can update existing or add new localizations using the lang:update console command:

php artisan lang:update

If in production you need to use a list of localizations through facades, you need to additionally install a dependency:

composer require laravel-lang/locales

We also recommend adding the call code to the post-update-cmd section of the scripts block in the composer.json file:

{ "scripts": { "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force", "@php artisan lang:update" ] } }

This will allow localization files to be automatically updated after dependency updates, rather than manually calling the php artisan lang:update console command.

Alternative

If you do not want to install all the dependencies for some reason, you can install each one separately:

composer require --dev laravel-lang/lang composer require --dev laravel-lang/actions composer require --dev laravel-lang/attributes composer require --dev laravel-lang/http-statuses composer require laravel-lang/locales composer require laravel-lang/locale-list composer require laravel-lang/native-country-names composer require laravel-lang/native-currency-names composer require laravel-lang/native-locale-names

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.

Lumen Framework

As a result of this message from the Laravel team, we do not officially support the Lumen Framework in our projects.

Last modified: 30 January 2024