PHPackages                             mtz-jaime/locale-middleware - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. mtz-jaime/locale-middleware

ActiveLibrary[Localization &amp; i18n](/categories/localization)

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.

00PHP

Since Jan 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mtz-jaime/locale-middleware)[ Packagist](https://packagist.org/packages/mtz-jaime/locale-middleware)[ RSS](/packages/mtz-jaime-locale-middleware/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Locale Middleware Package
=========================

[](#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.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

Install via Composer.

```
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.

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

```
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.

```
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*.

To download the geoIP binary file there are two options.

- (Option #1) You can find a free version [here](https://dev.maxmind.com/geoip/geoip2/geolite2) 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.
- (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
```

### Setting up the cookie

[](#setting-up-the-cookie)

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

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

### Testing the middleware

[](#testing-the-middleware)

This package offers you out of the box the possibility to test if the localization functionality is working.

Publish the needed views and translations using the following command:

```
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*.

Note: add the locale in uppercase

```
ENABLE_TEST_MIDDLEWARE=CH or
ENABLE_TEST_MIDDLEWARE=MX
```

Finally just access to the following link *''* and the middleware will be up and running

If you are switching between locales remember to clear the config cache of your application.

```
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

```
php artisan mtzJaime:remove-test-files
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/70a01f58ef6280a9ec9d2c55ef9236f0a20b51986df58c6fd6733fe3a182a360?d=identicon)[mtz-jaime](/maintainers/mtz-jaime)

---

Top Contributors

[![mtz-jaime](https://avatars.githubusercontent.com/u/16688100?v=4)](https://github.com/mtz-jaime "mtz-jaime (1 commits)")

### Embed Badge

![Health badge](/badges/mtz-jaime-locale-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/mtz-jaime-locale-middleware/health.svg)](https://phpackages.com/packages/mtz-jaime-locale-middleware)
```

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
