divineomega/laravel-domain-to-locale

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

v1.0.0 2019-05-22 21:57 UTC

This package is auto-updated.

Last update: 2024-04-23 20:40:43 UTC


README

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

Installation

To install the Laravel Domain To Locale package, just run the following Composer command from the root of your project.

composer require divineomega/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.

\DivineOmega\LaravelDomainToLocale\Http\Middleware\DomainToLocale::class,

After installation, the config file must be setup within your project. To do so, simply run the following Artisan command.

php artisan vendor:publish --provider="DivineOmega\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',

    ]

];

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.