PHPackages                             mcaskill/slim-polyglot - 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. [Framework](/categories/framework)
4. /
5. mcaskill/slim-polyglot

AbandonedArchivedLibrary[Framework](/categories/framework)

mcaskill/slim-polyglot
======================

Slim 3 language resolution middleware

v0.5.0(3y ago)41.7k51MITPHPPHP &gt;=5.5.0

Since Mar 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mcaskill/Slim-Polyglot)[ Packagist](https://packagist.org/packages/mcaskill/slim-polyglot)[ Docs](https://github.com/mcaskill/Slim-Polyglot)[ RSS](/packages/mcaskill-slim-polyglot/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (9)Dependencies (2)Versions (10)Used By (1)

Slim 3 Polyglot
===============

[](#slim-3-polyglot)

Resolves the response's current language based on the requested URI, the client's preferred language, and the available languages.

Alters the `ResponseInterface` to assign the `Content-Language` header.

Uses [willdurand/Negotiation](https://github.com/willdurand/Negotiation)to detect and negotiate the client language.

Install
-------

[](#install)

Via Composer:

```
composer require mcaskill/slim-polyglot
```

Requires Slim 3.

Usage
-----

[](#usage)

```
use Slim\App;
use McAskill\Slim\Polyglot\Polyglot;

$app = new App();

// Fetch DI Container
$container = $app->getContainer();

// Register Middleware
$app->add(new Polyglot([ 'en', 'fr', 'es' ]));

// Example route with ETag header
$app->get('/foo', function ($request, $response) {
	$language = $response->getHeader('Content-Language');

	// Handle response!
});

$app->run();
```

The Polyglot middleware can also accept callbacks that are executed after a language is chosen.

```
use Slim\App;
use McAskill\Slim\Polyglot\Polyglot;

$app = new App();

// Fetch DI Container
$container = $app->getContainer();

// Register Middleware
$app->add(
	new Polyglot([
		'languages' => [ 'en', 'fr', 'es' ],
		'fallbackLanguage' => 'fr',
		// Hooks to call after language is resolved
		'callbacks' => [
			function ($language) use ($container) {
				$container['environment']['language.current'] = $language;
			},
			[ 'MySuperApp', 'set_language' ]
		]
	])
);

// Example route with ETag header
$app->get('/foo', function ($request, $response) {
	$language = $this->environment['language.current'];

	// Handle response!
});

$app->run();
```

Testing
-------

[](#testing)

*TBD*

Notes
-----

[](#notes)

The language code may be formatted as ISO 639-1 alpha-2 (en), ISO 639-3 alpha-3 (msa), or ISO 639-1 alpha-2 combined with an ISO 3166-1 alpha-2 localization (zh-tw).

```
[ "en", "fr-CA" ]
```

When giving a list of languages to the Polyglot middleware, the first language is used as the fallback language. When switching to a language that is not in the list of supported languages, the first language is used instead.

Definitions:

- "language-fallback" — Default language; determined as the first among your supported languages.
- "language-preferred" — Preferred language(s); determined as the client's localization preferences.
- "language-current" — Current language; determined as the localization to use based on a cross-reference of the application's supported languages and the client's priority of preferred languages.

License
-------

[](#license)

The MIT License (MIT). Please see the [License File](LICENSE)for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.6% 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.

###  Release Activity

Cadence

Every ~256 days

Recently: every ~337 days

Total

9

Last Release

1350d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a4f39523b4b2837562ba0848a0327b8d340118d1ba87cb0f5d59b1d5cb6beba?d=identicon)[mcaskill](/maintainers/mcaskill)

---

Top Contributors

[![mcaskill](https://avatars.githubusercontent.com/u/29353?v=4)](https://github.com/mcaskill "mcaskill (22 commits)")[![Tarpsvo](https://avatars.githubusercontent.com/u/2018660?v=4)](https://github.com/Tarpsvo "Tarpsvo (2 commits)")[![guym4c](https://avatars.githubusercontent.com/u/2103489?v=4)](https://github.com/guym4c "guym4c (1 commits)")[![ironsmile](https://avatars.githubusercontent.com/u/50431?v=4)](https://github.com/ironsmile "ironsmile (1 commits)")[![pmous](https://avatars.githubusercontent.com/u/50670106?v=4)](https://github.com/pmous "pmous (1 commits)")[![tzkoshi](https://avatars.githubusercontent.com/u/3149847?v=4)](https://github.com/tzkoshi "tzkoshi (1 commits)")

---

Tags

middlewareframeworklanguageslimmultilingualpolylingual

### Embed Badge

![Health badge](/badges/mcaskill-slim-polyglot/health.svg)

```
[![Health](https://phpackages.com/badges/mcaskill-slim-polyglot/health.svg)](https://phpackages.com/packages/mcaskill-slim-polyglot)
```

###  Alternatives

[slim/csrf

Slim Framework 4 CSRF protection PSR-15 middleware

3512.1M100](/packages/slim-csrf)[slim/http-cache

Slim Framework HTTP cache middleware and service provider

1163.1M32](/packages/slim-http-cache)[davidepastore/slim-validation

A slim middleware for validation based on Respect/Validation

170227.3k3](/packages/davidepastore-slim-validation)[pavlakis/slim-cli

Making a mock GET request through the CLI and enabling the same application entry point on CLI scripts.

3693.1k3](/packages/pavlakis-slim-cli)[davidepastore/slim-restrict-route

A Slim middleware to restrict ip addresses that will access to your routes

2220.9k1](/packages/davidepastore-slim-restrict-route)[davidepastore/slim-config

A slim middleware to read configuration from different files based on hassankhan/config

339.0k1](/packages/davidepastore-slim-config)

PHPackages © 2026

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