PHPackages                             basteyy/php-localization-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. basteyy/php-localization-middleware

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

basteyy/php-localization-middleware
===================================

A middleware for handling language in your application

0.0.4(7mo ago)015ISCPHPPHP ^8.0 || ^8.1 || ^8.2 || ^8.3

Since Nov 15Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/basteyy/php-localization-middleware)[ Packagist](https://packagist.org/packages/basteyy/php-localization-middleware)[ RSS](/packages/basteyy-php-localization-middleware/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

LocalizationMiddleware
======================

[](#localizationmiddleware)

A PHP middleware for handling localization and language preferences in web applications.

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

[](#installation)

You can install this package via Composer. Run the following command:

```
composer require basteyy/php-localization-middleware
```

Usage
-----

[](#usage)

To use this middleware in your PHP application, follow these steps:

Create an instance of the LocalizationMiddleware class with your desired configuration and add it as middleware. For example:

```
    $app->add(new \basteyy\LocalizationMiddleware\LocalizationMiddleware(
        default_language: 'de',                     // Default language
        available_languages: ['de', 'ua', 'en'],    // Supported languages
        patch_requested_url: true,                  // Patch the requested url to remove the language in case there is one
        browser_overwrite_url: false,               // Overwrite the url language with the browser language
        patch_only_exactly_match: false             // Patch requested url only if the language is exactly matched (only when url contain a supported language)
    ));
```

The middleware will automatically determine the preferred language based on the request and set it as an attribute on the request object. You can access the language attribute using `$request->getAttribute('language')`.

Configuration
-------------

[](#configuration)

The LocalizationMiddleware class can be configured with the following options:

- `$default_language`: The default language to use when no preferred language is detected. It should be a two-letter language code (e.g., 'en').
- `$available_languages`: An array of supported languages, each represented by a two-letter language code (e.g., 'en', 'de', 'fr').
- `$patch_requested_url`: Set to true to patch the requested URL by removing the language prefix (e.g., '/en/...').
- `$browser_overwrite_url`: Set to true to overwrite the URL with the browser's preferred language even if the URL specifies a different language.
- `$patch_only_exactly_match`: Set to true, when only supported languages stripped from the url (path)

License
-------

[](#license)

ISC License

Copyright (c) 2023 basteyy

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance62

Regular maintenance activity

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% 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 ~244 days

Total

4

Last Release

229d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a735923bad41df312545d6b9b5f6ab585182f3553ef7633ec32a4caff1ccaf0d?d=identicon)[basteyy](/maintainers/basteyy)

---

Top Contributors

[![basteyy](https://avatars.githubusercontent.com/u/2758879?v=4)](https://github.com/basteyy "basteyy (14 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")

---

Tags

phpmiddlewarelanguage

### Embed Badge

![Health badge](/badges/basteyy-php-localization-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/basteyy-php-localization-middleware/health.svg)](https://phpackages.com/packages/basteyy-php-localization-middleware)
```

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k28.0M318](/packages/openai-php-client)[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.6k86.4k1](/packages/getgrav-grav)[cakephp/authentication

Authentication plugin for CakePHP

1214.1M106](/packages/cakephp-authentication)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M125](/packages/mezzio-mezzio)

PHPackages © 2026

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