Switch between multiple languages on your Laravel application, the easy way.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
resources/views
src
.editorconfig
.gitignore
.php_cs
LICENSE.md
README.md
composer.json

README.md

Latest Stable Version License Total Downloads

Laravel Polyglot

Not ready for production!

Switch between multiple languages on your Laravel application, the easy way.

Requirements

  • PHP 7.1+
  • Laravel 5.7+

Notes

This package assume that you want every language to behave like a separate website. There is no guessing, Laravel Polyglot won't do automatic switch to the user's language. From an SEO point of view, that's the recommanded way, because Google and others will be able to visit and index every one of them (see amazon.com, apple.com, google.com, etc). More on the topic here: https://support.google.com/webmasters/answer/182192

Installation

composer require benjamincrozat/laravel-polyglot

Once it's done, register Laravel Polyglot before RouteServiceProvider in config/app.php:

'providers' => [
    BC\Laravel\Polyglot\PolyglotServiceProvider::class,
    App\Providers\RouteServiceProvider::class,
]

Then, go to app/Providers/RouteServiceProvider.php and add the prefix() method in case you are using the directories driver. If you're not, the prefix won't have any effect.

protected function mapWebRoutes()
{
    Route::prefix(polyglot()->prefix())
        ->middleware('web')
        ->namespace($this->namespace)
        ->group(base_path('routes/web.php'));
}

Now, take a look at config/polyglot.php and change it as you wish.

Usage

Once you configured Laravel Polyglot, there are views that are here to help on the SEO and the language switcher:

<!DOCTYPE html>
<html>
    <head>
        @include('polyglot::links')
    </head>
    <body>
        @include('polyglot::switcher')
    </body>
</html>

Obviously, you are free to not use them and make your own!

ToDo

License

WTFPL