jord-jd/laravel-domain-to-locale

Change your Laravel app's locale based on the domain name

Maintainers

Package info

github.com/Jord-JD/laravel-domain-to-locale

pkg:composer/jord-jd/laravel-domain-to-locale

Transparency log

Fund package maintenance!

DivineOmega

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

v3.1.0 2026-07-18 10:16 UTC

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.