Translate a URI or individual slugs.
opgginc/codezero-laravel-uri-translator is a Laravel package for translate a uri or individual slugs..
It currently has 0 GitHub stars and 132.344 downloads on Packagist (latest version 2.0.3).
Install it with composer require opgginc/codezero-laravel-uri-translator.
Discover more Laravel packages by opgginc
or browse all Laravel packages to compare alternatives.
Last updated
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.
Install this package with Composer:
composer require opgginc/codezero-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.
Use the Lang::uri() macro when registering routes:
Route::get(Lang::uri('hello/world'), [Controller::class, 'index']);
The URI macro accepts 2 additional parameters:
Lang::uri('hello/world', 'fr', 'my-package');
You can also use trans()->uri('hello/world') instead of Lang::uri('hello/world').
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}');
composer test
This package is a fork of the original work by Ivan Vermeyen. We are deeply saddened to share that Ivan has passed away. In memory of his excellent contribution to the Laravel community, we have forked this package to maintain and extend its functionality for newer Laravel versions. We extend our condolences to Ivan's family and friends.
This project is maintained by OP.GG Inc. If you discover any security related issues, please use the issue tracker.
This package is a fork of codezero/laravel-uri-translator, updated to support Laravel 13.
The MIT License (MIT). Please see License File for more information.