Download the PHP package josiasmontag/laravel-localization without Composer
On this page you can find all versions of the php package josiasmontag/laravel-localization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download josiasmontag/laravel-localization
More information about josiasmontag/laravel-localization
Files in josiasmontag/laravel-localization
Package laravel-localization
Short Description Localization for Laravel framework
License MIT
Homepage https://github.com/josiasmontag/laravel-localization
Informations about the package laravel-localization
Laravel Localization
Introduction
The Laravel Localization package is built for Laravel 5.5+ and provides:
- [x] Localized routes with language URL prefixes.
- [x] Domain based localized routes.
- [x] Middleware to detect user language based on HTTP header and cookie.
- [x] Redirect the user to the localized version.
- [x] Possibility to hide the language URL prefix for the default language.
- [x] Possibility to localize a subset of routes only.
- [x] Language Switcher and Hreflang Meta Tags
- [x] Patched
route()
method to use localized routes whenever possible. - [x] Compatibility with
artisan route:cache
.
Installation
To get started, use Composer to add the package to your project's dependencies:
composer require josiasmontag/laravel-localization
Add the HandleLocalization
Middleware to the web
group in App/Http/Kernel.php
:
Configuration
To publish the config file to config/localization.php
:
php artisan vendor:publish --provider "Lunaweb\Localization\LocalizationServiceProvider"
Default configuration:
Usage
Prefix Based Localized Routes
To add localized routes with language prefixes, edit your routes/web.php
and use localizedRoutesGroup
helper:
Under the hood this will create the following routes for you:
Route | Route Name | Language |
---|---|---|
/ |
index |
English (Default Language) |
/de |
de.index |
German |
/fr |
fr.index |
French |
/register |
register |
English (Default Language) |
/de/register |
de.register |
German |
/fr/register |
fr.register |
French |
Domain Based Localized Routes
To add domain-based localized routes, add the localized domains to your config/localization.php
configuration:
The example from above will then create the following routes:
Route | Route Name | Language |
---|---|---|
domain.com |
index |
English (Default Language) |
domain.de |
de.index |
German |
domain.fr |
fr.index |
French |
domain.com/register |
register |
English (Default Language) |
domain.de/register |
de.register |
German |
domain.fr/register |
fr.register |
French |
Localization Specific Routes
You can manually create language specific routes using the localization()
macro.
Helpers
Localized route()
route()
will automatically use the localized version, if there is any available. Using the example from above, route('index')
resolves to the index
, de.index
or fr.index
route depending on the user's language.
Check if the current route is localized
or...