jord-jd / laravel-domain-to-locale
Change your Laravel app's locale based on the domain name
Package info
github.com/Jord-JD/laravel-domain-to-locale
pkg:composer/jord-jd/laravel-domain-to-locale
Fund package maintenance!
Requires
- php: >=7.1
- laravel/framework: ^5.6||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0||^12.0||^13.0
Requires (Dev)
- phpunit/phpunit: ^7.5||^9.6||^12.0
Replaces
This package is auto-updated.
Last update: 2026-07-18 10:16:47 UTC
README
Change your Laravel app's locale based on the domain name.
Supports Laravel 5.6 through 13. The package configuration is loaded automatically; publishing it is only required when you want to customise mappings.
Installation
To install the Laravel Domain To Locale package, just run the following Composer command from the root of your project.
composer require jord-jd/laravel-domain-to-locale
Setup
This package requires you to register a global middleware
within your app\Http\Kernel.php file. Just add the
line below to your $middleware array.
\JordJD\LaravelDomainToLocale\Http\Middleware\DomainToLocale::class,
To customise the mappings, publish the config file with:
php artisan vendor:publish --provider="JordJD\LaravelDomainToLocale\ServiceProvider"
Configuration
The published configuration file for this package
can be found at config/domain-to-locale.php.
This file defines a map between domain name and locale,
as shown in the example below.
<?php return [ // Define the mapping from domain name to locale 'map' => [ 'example.com' => 'en', '*.example.co.uk' => 'en', 'example.pl' => 'pl', 'example.de' => 'de', 'example.fr' => 'fr', ], // Optional locale when no mapping matches. 'fallback' => null, ];
Adding new lines to the map array will allow you to
specify which domain names should set which locales.
Once configured, everything else is automatic.
Exact host mappings take precedence. A wildcard such as *.example.co.uk matches shop.example.co.uk and deeper subdomains, but not the bare example.co.uk host. Matching is case-insensitive and ignores a trailing dot.