Laravel Strict Domain Checking for Laravel

A Laravel package facilitating efficient locale determination based on domain names, simplifying multi-language website development.

View the Project on GitHub ByteFlick/laravel-domain-localization

Domain-Based Localization for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.