mimmi20/mezzio-setlocale-middleware

Provides a Middleware to set the Locale and the language to a translator

2.0.2 2025-08-02 11:17 UTC

This package is auto-updated.

Last update: 2025-08-07 02:27:08 UTC


README

Latest Stable Version Latest Unstable Version License

Code Status

codecov Average time to resolve an issue Percentage of issues still open Mutation testing badge

Introduction

This component provides middleware for Mezzio and PSR-7 applications to set the locale and the language for a translator based on the HTTP_ACCEPT_LANGUAGE Header.

Requirements

This library requires

  • PHP 8.3+.
  • a translator

Installation

Run

composer require mimmi20/mezzio-setlocale-middleware

Add the Middleware to the pipeline

<?php
return [
    'middleware' => [
        // ...
        \Mimmi20\Mezzio\Middleware\SetLocaleMiddleware::class, // <-- Add this line
        // ... <-- any middleware or request handler wich uses the translator
    ],
];

If you need the Translator for the Routing, you have to add the Middleware in the Pipeline before the Routing.

    $app->pipe(\Mimmi20\Mezzio\Middleware\SetLocaleMiddleware::class); // <-- Add this line

    // Register the routing middleware in the middleware pipeline.
    // This middleware registers the Mezzio\Router\RouteResult request attribute.
    $app->pipe(RouteMiddleware::class);

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.