Looking to hire Laravel developers? Try LaraJobs
This package is not available.

laravel-language-detect maintained by j-hansol

Description
This is a package for language detection and configuration for Laravel.
Author
Last update
2024/06/10 20:52 (dev-main)
License
Links
Downloads
13

Comments
comments powered by Disqus

Language detection and Setting for Laravel

License License

It provides a very simple function for detecting and setting the language in a website or backend service running on the Laravel framework.

installation

You can simply install it with the command below from the project path under development.

composer require j-hansol/laravel-language-detect

Add the following content to the .env file. If not added, it will be set to the contents of the language_detect.php file included in the package.

APP_LOCALES="ko,en"
APP_LOCALE_SEGMENT=1
APP_LOCALE_FIELD_NAME=language

How to use

To detect and set the language, simply add middleware to the routing path as shown below.

Route::prefix('{locale}')->group(function() {
    Route::get('test', [\App\Http\Controllers\LanguageSettingTest::class, 'showResult'])
        ->middleware('set_language');
});

Customize your preferences file

If you have made the necessary settings in .env, this step will not be necessary. Nevertheless, if you want to change the settings, you can change the contents after executing the command below.

php artisan vendor:publish --tag=language-detect