PHPackages                             georgechaduneli/laravel-localization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. georgechaduneli/laravel-localization

ActiveLibrary

georgechaduneli/laravel-localization
====================================

Easy localization for Laravel

05PHPCI failing

Since Jun 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/georgechaduneli/laravel-localization)[ Packagist](https://packagist.org/packages/georgechaduneli/laravel-localization)[ RSS](/packages/georgechaduneli-laravel-localization/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Localization
====================

[](#laravel-localization)

[![Join the chat at https://gitter.im/mcamara/laravel-localization](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/mcamara/laravel-localization?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Latest Stable Version](https://camo.githubusercontent.com/607c5caf11da2679850f2ac88101ad7a034eb01447078f7abd24a8434e826d4a/68747470733a2f2f706f7365722e707567782e6f72672f6d63616d6172612f6c61726176656c2d6c6f63616c697a6174696f6e2f76657273696f6e2e706e67)](https://packagist.org/packages/mcamara/laravel-localization) [![Total Downloads](https://camo.githubusercontent.com/4c163356b80cbd79e46fc79dbfe593609579ac4df6e56b11bfa189bd2a5fc528/68747470733a2f2f706f7365722e707567782e6f72672f6d63616d6172612f6c61726176656c2d6c6f63616c697a6174696f6e2f642f746f74616c2e706e67)](https://packagist.org/packages/mcamara/laravel-localization) [![Build Status](https://camo.githubusercontent.com/a6757316aa8695da8711dbac4dcfc542247b951dc1919089558f858a49e69c86/68747470733a2f2f7472617669732d63692e6f72672f6d63616d6172612f6c61726176656c2d6c6f63616c697a6174696f6e2e706e67)](https://travis-ci.org/mcamara/laravel-localization)

Easy i18n localization for Laravel, an useful tool to combine with Laravel localization classes.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
    - [Composer](#composer)
    - [Manually](#manually)
    - [Laravel](#laravel)
- [Usage](#usage)
    - [Middleware](#middleware)
- [Helpers](#helpers)
- [Translated Routes](#translated-routes)
- [Config](#config)
    - [Config files](#config-files)
    - [Service providers](#service-providers)
- [Caching routes](#caching-routes)
- [Changelog](#changelog)
- [License](#license)

Laravel compatibility
---------------------

[](#laravel-compatibility)

Laravellaravel-localization4.0.x0.13.x4.1.x0.13.x4.2.x0.15.x5.0.x/5.1.x1.0.x5.2.x-5.4.x (PHP 7 not required)1.2.x5.2.x-5.5.x (PHP 7 required)1.3.xInstallation
------------

[](#installation)

Install the package via composer: `composer require mcamara/laravel-localization`

In Laravel 5.5, the service provider and facade will automatically get registered. For older versions of the framework, follow the steps below:

Register the service provider in `config/app.php`

```
        'providers' => [
		// [...]
                Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class,
        ],
```

You may also register the `LaravelLocalization` facade:

```
        'aliases' => [
		// [...]
                'LaravelLocalization' => Mcamara\LaravelLocalization\Facades\LaravelLocalization::class,
        ],
```

Usage
-----

[](#usage)

Laravel Localization uses the URL given for the request. In order to achieve this purpose, a route group should be added into the `routes.php` file. It will filter all pages that must be localized.

```
// app/Http/routes.php

Route::group(['prefix' => LaravelLocalization::setLocale()], function()
{
	/** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/
	Route::get('/', function()
	{
		return View::make('hello');
	});

	Route::get('test',function(){
		return View::make('test');
	});
});

/** OTHER PAGES THAT SHOULD NOT BE LOCALIZED **/
```

Once this route group is added to the routes file, a user can access all locales added into `supportedLocales` ('en' and 'es' by default, look at the config section to change that option). For example, a user can now access two different locales, using the following addresses:

```
http://url-to-laravel/en
http://url-to-laravel/es
http://url-to-laravel

```

If the locale is not present in the url or it is not defined in `supportedLocales`, the system will use the application default locale or the user's browser default locale (if defined in config file).

Once the locale is defined, the locale variable will be stored in a session (if the middleware is enabled), so it is not necessary to write the /lang/ section in the url after defining it once, using the last known locale for the user. If the user accesses to a different locale this session value would be changed, translating any other page he visits with the last chosen locale.

Template files and all locale files should follow the [Lang class](http://laravel.com/docs/5.0/localization).

### Middleware

[](#middleware)

Moreover, this package includes a middleware object to redirect all "non-localized" routes to the corresponding "localized".

So, if a user navigates to  and the system has this middleware active and 'en' as the current locale for this user, it would redirect (301) him automatically to . This is mainly used to avoid duplicate content and improve SEO performance.

To do so, you have to register the middleware in the `app/Http/Kernel.php` file like this:

```
