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

ActiveProject

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

A middleware for handling language in your application

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

Since Nov 15Pushed 6mo 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 1mo ago

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

36

—

LowBetter than 82% of packages

Maintenance69

Regular maintenance activity

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

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

183d 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.8k22.6M232](/packages/openai-php-client)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[cakephp/authentication

Authentication plugin for CakePHP

1153.6M67](/packages/cakephp-authentication)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[openswoole/core

Openswoole core library

181.1M32](/packages/openswoole-core)

PHPackages © 2026

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