divineomega / laravel-domain-to-locale
Change your Laravel app's locale based on the domain name
Fund package maintenance!
DivineOmega
Requires
- php: >=7.1
- laravel/framework: ^5.6
Requires (Dev)
- orchestra/testbench: ^3.8
This package is auto-updated.
Last update: 2024-11-23 22:06:29 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.