Download the PHP package dongrim/laravel-localization without Composer
On this page you can find all versions of the php package dongrim/laravel-localization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dongrim/laravel-localization
More information about dongrim/laravel-localization
Files in dongrim/laravel-localization
Package laravel-localization
Short Description Easy localization for Laravel
License MIT
Informations about the package laravel-localization
Easy i18n localization for Laravel.
The package offers the following:
- Detect language from browser
- Smart redirects (Save locale in session)
- Smart routing (Define your routes only once, no matter how many languages you use)
- Option to hide default locale in url
Table of Contents
- Installation
- Register Middleware
- Usage
- Localization from database
- Recommended
- Helpers
- Caching routes
Laravel compatibility
Laravel | laravel-localization |
---|---|
6.0-9.x (PHP 7 required) | 1.0.x |
Installation
Install the package via composer: composer require dongrim/laravel-localization
Config Files
In order to edit the default configuration you may execute:
After that, config/localization.php
will be created.
The configuration options are:
- useAcceptLanguageHeader If true, then automatically detect language from browser.
- hideDefaultLocaleInURL If true, then do not show default locale in url.
- driver two drivers are supported to access (Default: config file) the list of locales:
- The configuration file config/localization.php
- database
- supportedLocales Languages of your app (Default: English & Spanish).
- localesMapping Rename url locales.
Register Middleware
You may register the package middleware in the app/Http/Kernel.php
file:
Usage
Add the following to your routes file:
Localization database
If you want to use the list of locales from the database change config/localization.php .
- specify driver
- set model_namespace
- set locale_key Then in the model responsible for this list:
- trait Dongrim\LaravelLocalization\Traits\Localizable
For example:
Recommended
Use named routes for more an easy way to access url localization.
A locale other than the default locale will be automatically added to the url
Helpers
This package comes with helpers.
Locales collection
List of all available locales
Default locale
When you set useAcceptLanguageHeader = true, to find out the default language you need to use
Caching routes
To cache your routes, use: