2017 © Pedro Peláez
 

library locale-middleware

This package will help you to localize your application depending from where a user is coming using geoIP, also offers the possibility to overwrite the default language provided via geoIP using a cookie.

image

mtz-jaime/locale-middleware

This package will help you to localize your application depending from where a user is coming using geoIP, also offers the possibility to overwrite the default language provided via geoIP using a cookie.

  • Saturday, January 20, 2018
  • by mtz-jaime
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Locale Middleware Package

This package will help you to localize your application depending from where a user is coming using geoIP, also offers the possibility to overwrite the default language provided via geoIP using a cookie., (*1)

Getting Started

Installation

Install via Composer., (*2)

composer require mtz-jaime/locale-middleware

If you are using Laravel 5.5 this package already includes the auto discovery package. If for some reason you decided to remove this functionality on your application, add the service provider into your application config., (*3)

Do this by adding the following line to the 'providers' section of the application config (usually config/app.php):, (*4)

MtzJaime\LocaleMiddleware\LocaleMiddlewareServiceProvider::class,

Publish the config file in order to have control to decide which languages your applications is going to support, also to enable the middleware functionality., (*5)

php artisan vendor:publish --provider="MtzJaime\LocaleMiddleware\LocaleMiddlewareServiceProvider" --tag="config"

To enable the middleware add the following variable ENABLE_LOCALE_MIDDLEWARE=true in your .env file, to disable the middleware just delete the variable or change it to false., (*6)

To download the geoIP binary file there are two options. - (Option #1) You can find a free version here of the file GeoLite2 Country by MaxMind DB. Also you need to add the following variable GEOIP_MAXMIND_DATABASE='storage/path/of/the/binary' in your .env file, as a good practice is recommended to stored this kind of files under your storage folder., (*7)

  • (Option #2) You can simply run the following command and let the package do the rest. You don't need to add here the .env variable
php artisan mtzJaime:get-geoIP

On the file app/Http/Middleware/EncryptCookies.php add under $except array the value 'visitLocale',, (*8)

You can take a look and create your own version of the LocaleCookieController.php (vendor/mtz-jaime/locale-middleware/src/LocaleCookieController.php), (*9)

Testing the middleware

This package offers you out of the box the possibility to test if the localization functionality is working., (*10)

Publish the needed views and translations using the following command:, (*11)

php artisan vendor:publish --provider="MtzJaime\LocaleMiddleware\LocaleMiddlewareServiceProvider" --tag="test"

Then add in your .env file the following variable ENABLE_TEST_MIDDLEWARE=LOCALE this variable can be set for any of the supported locales present on the config file LocaleMiddleware., (*12)

Note: add the locale in uppercase, (*13)

ENABLE_TEST_MIDDLEWARE=CH or
ENABLE_TEST_MIDDLEWARE=MX 

Finally just access to the following link 'http://your.app/middleware/test' and the middleware will be up and running, (*14)

If you are switching between locales remember to clear the config cache of your application., (*15)

php artisan config:clear

To remove the testing files just run the following command and delete manually the variable that you added in your .env file, (*16)

php artisan mtzJaime:remove-test-files

The Versions

20/01 2018

dev-master

9999999-dev

This package will help you to localize your application depending from where a user is coming using geoIP, also offers the possibility to overwrite the default language provided via geoIP using a cookie.

  Sources   Download

MIT

The Requires

 

by Jaime Martinez

laravel middleware geoip locale