Looking to hire Laravel developers? Try LaraJobs

laravel-uri-translator maintained by parfaitementweb

Description
Translate a URI or individual slugs.
Last update
2026/06/10 11:15 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

Laravel URI Translator

GitHub release Laravel License Build Status Total Downloads

This package registers a macro for the Laravel Translator class. This will allow you to translate individual URI slugs, while ignoring parameter placeholders.

Parameters will not be translated by this macro. That remains the responsibility of your code.

Maintained fork. This is a community-maintained fork of the original codezero-be/laravel-uri-translator by Ivan Vermeyen, updated to support Laravel 12 and 13. All credit for the original work goes to the CodeZero team.

✅ Requirements

  • PHP >= 8.3
  • Laravel 12 or 13

📦 Install

Install this package with Composer:

composer require parfaitementweb/laravel-uri-translator

Laravel will automatically register the ServiceProvider.

In your app's lang folder, create subdirectories for every locale you want to have translations for.

Next create a routes.php file in each of those directories.

lang/
  ├── en/
  │    └── routes.php
  └── nl/
       └── routes.php

Return an array of translations from the routes.php files.

🚀 Usage

Use the Lang::uri() macro when registering routes:

Route::get(Lang::uri('hello/world'), [Controller::class, 'index']);

The URI macro accepts 2 additional parameters:

  1. A locale, in case you need translations to a locale other than the current app locale.
  2. A namespace, in case your translation files reside in a package.
Lang::uri('hello/world', 'fr', 'my-package');

You can also use trans()->uri('hello/world') instead of Lang::uri('hello/world').

🔌 Example

Using these example translations:

// lang/nl/routes.php
return [
    'hello' => 'hallo',
    'world' => 'wereld',
    'override/hello/world' => 'something/very/different',
    'hello/world/{parameter}' => 'uri/with/{parameter}',
];

These are possible translation results:

// Translate every slug individually
// Translates to: 'hallo/wereld'
Lang::uri('hello/world');

// Keep original slug when missing translation
// Translates to: 'hallo/big/wereld'
Lang::uri('hello/big/world');

// Translate slugs, but not parameter placeholders
// Translates to: 'hallo/{world}'
Lang::uri('hello/{world}');

// Translate full URIs if an exact translation exists
// Translates to: 'something/very/different'
Lang::uri('override/hello/world');

// Translate full URIs if an exact translation exists (with placeholder)
// Translates to: 'uri/with/{parameter}'
Lang::uri('hello/world/{parameter}');

🚧 Testing

composer test

☕️ Credits

🔒 Security

If you discover any security related issues, please e-mail me instead of using the issue tracker.

📑 Changelog

A complete list of all notable changes to this package can be found on the releases page.

📜 License

The MIT License (MIT). Please see License File for more information.