PHPackages                             dijix/setlocale - 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. dijix/setlocale

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

dijix/setlocale
===============

Slim Framework middleware to set your applications locale

28641PHP

Since Oct 6Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dijitaltrix/SetLocale)[ Packagist](https://packagist.org/packages/dijix/setlocale)[ RSS](/packages/dijix-setlocale/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SetLocale
=========

[](#setlocale)

[![Build Status](https://camo.githubusercontent.com/b141ea50efe24493dbadc240bfdcfd7aacc373c279c22ba54d1486c058cc65b2/68747470733a2f2f7472617669732d63692e6f72672f64696a6974616c747269782f505352372d5365744c6f63616c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dijitaltrix/PSR7-SetLocale.svg?branch=master)[![Total Downloads](https://camo.githubusercontent.com/d8fbdb1085532e1d68be8188cdd38e73bf1357df31e6877215d52c2bdb2fa335/68747470733a2f2f706f7365722e707567782e6f72672f64696a69782f7365746c6f63616c652f646f776e6c6f616473)](https://packagist.org/packages/dijix/setlocale)[![License](https://camo.githubusercontent.com/ecdd26af26fc17243f29e9c57e46081eef1caf2873ee101a79694bdd656ada13/68747470733a2f2f706f7365722e707567782e6f72672f64696a69782f7365746c6f63616c652f6c6963656e7365)](https://packagist.org/packages/dijix/setlocale)

Description
-----------

[](#description)

Slim Framework middleware to set your applications locale

This middleware sets your applications locale to the best match between your applications supported locales and your visitors preferred locales.

It's designed to be used with the [Slim Framework](https://www.slimframework.com) but is PSR7 compatible so should work elsewhere too.

The visitors locale is determined in this order:

- An override passed to the middleware constructor e.g. from an existing cookie/session
- The first segment of the URI eg: example.com/en/welcome or example.com/en-gb/welcome.
- The users browser accept-language header, where it selects the best match
- A default passed locale eg: en\_GB, used as a fallback if none of the above match

When a match has been found the middleware sets:

- The request attribute 'locale'
- The response 'Content-language' header
- It will set the environment by calling setlocale(LC\_ALL) on the matched locale - this can be toggled with the set\_locale flag.

Installation
------------

[](#installation)

Install via composer

```
$ composer require dijix/setlocale
```

Usage
-----

[](#usage)

```
// In Slim PHP framework 3

// add the middleware to your app, often in the middleware.php or dependencies.php file

// pass your settings as an array to the constructor.
$app->add(new Dijix\Locale\setLocaleMiddleware([

	// set the locales supported by your application
	"app_locales" => ["de_DE", "en_GB", "fr_FR", "pt_PT"],

	// set a default locale to fallback on if no match is found
	"app_default" => "en_GB",

	// call PHP setlocale(LC_ALL) to set the visitors locale?
	"set_locale" => true,

	// strict or partial matching of the locale codes, e.g. "en" matches "en_GB"
	"strict_match" => false,

	// override uri/headers locale, useful when setting locale from a cookie or user session
	"override" => "pt_PT"

]));
```

The locale middleware will set a request attribute which can be accessed as follows:

```
$locale = $request->getAttribute('locale');		// sets $locale to "en_GB"
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

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/83d4562b4c108bb6a0a7b02a32b446ab863159c5d00de756b5e0d6bc16a8e544?d=identicon)[dijitaltrix](/maintainers/dijitaltrix)

---

Top Contributors

[![dijitaltrix](https://avatars.githubusercontent.com/u/3773564?v=4)](https://github.com/dijitaltrix "dijitaltrix (25 commits)")

### Embed Badge

![Health badge](/badges/dijix-setlocale/health.svg)

```
[![Health](https://phpackages.com/badges/dijix-setlocale/health.svg)](https://phpackages.com/packages/dijix-setlocale)
```

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.0k](/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.4M491](/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)
