2017 © Pedro Peláez
 

library laravel-languages

Using different languages in the Laravel

image

zagovorichev/laravel-languages

Using different languages in the Laravel

  • Friday, April 20, 2018
  • by zagovorichev
  • Repository
  • 1 Watchers
  • 0 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Multi language Laravel Plugin

This package pulls in the framework agnostic Language Manager and provides seamless integration with Laravel 5., (*1)

What is it?

Language manager: you can choose new language and it will be placed as App::setLocale($lang), (*2)

Language will be saved in SESSION and/or COOKIE, (*3)

Also you can use URL, (*4)

http://www.example.com/article/1?lang=en => http://en.example.com/en/article/1 

Installation

composer require zagovorichev/laravel-languages, (*5)

Add to the app.php (by default in /laravel/config/app.php) lines:, (*6)

'providers' => [
    // ...
    Zagovorichev\Laravel\Languages\LanguageServiceProvider::class,
]

And new middleware into the Kernel.php (look in /laravel/app/Http/Kernel.php), (*7)

protected $middlewareGroups = [
        'web' => [
            // ...
            \Zagovorichev\Laravel\Languages\Http\Middleware\LanguagesMiddleware\LanguagesMiddleware::class,
        ],
    ];

Usage

Language manager provides working with sessions, cookies, path and domain., (*8)

For changing system language send request with input lang. For example: ?lang=es and in application you will have Spain locale., (*9)

All configurations stored in the languages.php file.
For making your own configuration copy file /laravel/vendor/zagovorichev/laravel-languages/config/languages.php to the folder /laravel/config/., (*10)

If you need simple language manager you can use only 'session' and 'cookie' modes. Then you don't need to configure anything more., (*11)

Domain Map

For using DomainMapManger in your configuration file you should matched languages and domains, (*12)

'domainMap' => [
    'en' => 'www.example.com',
    'es' => 'es.example.com',
    'ua' => 'www.example.ua',
],

:warning: Notice: Please, use only DomainMap or Domain modes, otherwise the behaviour will be unpredictable., (*13)

Domain

Also you can provide regular expression in the configuration file., (*14)

'domainRegExp' => [
    'reg' => '|^(http://)([a-z]{2})[\.]{0,1}(example\.com.*)$|ui',
    'langPart' => 2,
]

And as a result you will have http://www.example.en/post/234 => http://en.example.com/post/234 => http://es.example.com/post/234, (*15)

:warning: Notice: Please, use only DomainMap or Domain modes, otherwise the behaviour will be unpredictable., (*16)

Path

Similar to domains, you can provide regular expression:, (*17)

'pathRegExp' => [
     'reg' => '|([a-z]{2})(/.*)|ui',
     'langPart' => 1, // lang part will be replaced with new lang
 ],

Modes of the languages manager

Each store has its own manager., (*18)

  • session - store in the $_SESSION
  • cookie - store in the browser $_COOKIES
  • domainMap - you can define map if you have different domain which can't be described with simple regular expression
  • domain - use domain name for determining current language (www.example.com, en.example.com, es.example.com...)
  • path - use uri for language example.com/en/address

Requirements

  • PHP 5.6
  • Laravel 5.3

License

This package is licensed under the MIT license, (*19)

The Versions

20/04 2018

dev-master

9999999-dev https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

20/04 2018

dev-develop

dev-develop https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

20/04 2018

v3.0.0

3.0.0.0 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

20/04 2018

dev-release-3.0.0

dev-release-3.0.0 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

20/04 2018

dev-feature/laravel-5.6

dev-feature/laravel-5.6 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

03/04 2017

v2.0.0

2.0.0.0 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

03/04 2017

dev-release-2.0.0

dev-release-2.0.0 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

21/11 2016

v1.1.1

1.1.1.0 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

29/10 2016

v1.1.0

1.1.0.0 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session

28/10 2016

v1.0.0

1.0.0.0 https://blog-tree.com

Using different languages in the Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Zagovorichev

laravel domain cookie localization translate session