Prevent Route Parameter Translation in Mezzio with Laminas\I18n Integration

I am encountering an issue where the route parameter in my Mezzio application seems to be causing errors due to unintended translation behavior.

Here is my route configuration for editing a Locale:

// Edit Locale Route
[
    'name'            => 'web.locales.edit',
    'path'            => '/locales/edit/{id:\d+}',
    'middleware'      => [
        Mezzio\Session\SessionMiddleware::class,
        Mezzio\Csrf\CsrfMiddleware::class,
        \Web\Locales\LocalesEditHandler::class,
    ],
    'allowed_methods' => ['GET', 'POST'],
],

The problem occurs when the {id} parameter is included in the route path. Specifically:

  • If I change the route to /locales/edit (without {id}), the route works fine.
  • When {id} is added as a dynamic segment, I encounter an error: “No Translator provided”.

I am using:

  • Mezzio with Laminas\Router (and Laminas\I18n installed)
  • Dynamic route matching with Segment type
  • Translator is configured (likely through Laminas\I18n)

What I’ve Tried:

  1. I ensured that the route itself does not include translatable content.
  2. I tested removing Laminas\I18n entirely, but the problem persisted.
  3. I attempted switching to the Literal route type instead of Segment, but this doesn’t solve the issue since Literal routes do not support dynamic parameters.

Questions:

  1. Is there a way to prevent the translator from affecting the route parameters like {id}?
  2. Is this a configuration issue with Laminas\I18n or the router setup?
  3. How can I explicitly disable translation for a specific route or ensure dynamic segments like {id} are treated as plain route parameters?

Environment:

  • Mezzio: 3.x
  • Laminas\Router: Latest
  • Laminas\I18n: Installed
  • PHP: 8.1.x

Any guidance on how to resolve this issue or prevent the translator from interfering with dynamic route parameters would be greatly appreciated. Thank you!

Instead of {id} try to use :id.

Thanks a ton, that worked!!