byteflick / laravel-domain-localization
A Laravel package facilitating efficient locale determination based on domain names, simplifying multi-language website development.
Fund package maintenance!
ByteFlick
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.22
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is not auto-updated.
Last update: 2024-12-09 19:48:37 UTC
README
Domain-Based Localization for Laravel
Introducing "Domain-Based Localization for Laravel" – a powerful Laravel package designed to streamline the localization process for multi-language web applications. With seamless integration, this package empowers developers to effortlessly assign locales based on domain names, simplifying the management of language variations across diverse web environments. Experience streamlined localization management and enhanced user experiences with Domain-Based Localization for Laravel.
Installation
You can install the package via composer:
composer require byteflick/laravel-domain-localization
You can publish the config file with:
php artisan vendor:publish --provider="ByteFlick\LaravelDomainLocalization\LaravelDomainLocalizationServiceProvider"
This is the contents of the published config file:
Note: If you set the mode to strict
then if the middleware cannot find a locale it aborts the request.
return [ 'mode' => 'loose', // strict or loose 'locales' => [ 'en' => ['name' => 'English', 'domain' => 'localhost.com'], // 'es' => ['name' => 'Spanish', 'domain' => 'localhost.com.tr'], // 'tr' => ['name' => 'Turkish', 'domain' => 'localhost.com.es'], // ... More locales can be added here. ] ];
Usage
Step 1: Publish the Config File
Publish the config file via the command below and configure it according to your needs.
php artisan vendor:publish --provider="ByteFlick\LaravelDomainLocalization\LaravelDomainLocalizationServiceProvider"
Step 2: Apply the Middleware
On Specific Routes Only
You can add the middleware to individual routes or apply it via a route group.
Globally For Laravel 11
Append the middleware to your default middlewares into your bootstrap/app.php
via the code below.
->withMiddleware(function (Middleware $middleware) { $middleware->append(\ByteFlick\LaravelDomainLocalization\Middlewares\HandleLocalizationViaDomain::class); })
Globally For Laravel 10
Add the middleware to your default middlewares into your App\Http\Kernel.php
via the code below.
protected $middleware = [ \ByteFlick\LaravelDomainLocalization\Middlewares\HandleLocalizationViaDomain::class, ];
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.