PHPackages                             ofat/laravel-translatable-routes - 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. ofat/laravel-translatable-routes

ActiveLibrary

ofat/laravel-translatable-routes
================================

Laravel package for translatable routes

v1.0.1(4y ago)245MITPHPPHP ^8.0

Since Apr 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ofat/laravel-translatable-routes)[ Packagist](https://packagist.org/packages/ofat/laravel-translatable-routes)[ RSS](/packages/ofat-laravel-translatable-routes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

[![](https://camo.githubusercontent.com/b94693782ad45d66d30c1d0568df51c6de2e69845402f7bc55fd759757d1fa30/68747470733a2f2f7777772e6e7973656e6174652e676f762f73697465732f64656661756c742f66696c65732f7374796c65732f373630783337372f7075626c69632f70726573732d72656c656173652f6d61696e2d696d6167652f66625f6c696e6b5f737570706f72745f756b7261696e653732372e6a7067)](https://supportukrainenow.org)

Package to make Laravel routes translatable
===========================================

[](#package-to-make-laravel-routes-translatable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/951ad67287dfcff1cc1a0732e6d0d79b28ac7dc1c4a8d36cb34e0ce091884bdb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6661742f6c61726176656c2d7472616e736c617461626c652d726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ofat/laravel-translatable-routes)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This package provides you possibility to translate your urls. For example:

```
EN: /en/country/germany, /en/about-us
DE: /de/land/deutschland, /de/uber-uns

```

It is very useful for good search engine optimization (seo).

Installation
------------

[](#installation)

1. Install package via composer:

```
composer require ofat/laravel-translatable-routes
```

2. Add your translations to resource/lang like usual Laravel translations.

resources/lang/en.json:

```
{
    "country": "Country",
    "about-us": "About us"
}
```

resources/lang/de.json:

```
{
    "country": "Land",
    "about-us": "Uber uns"
}
```

3. Define your supported locales in config file:

config/translatable-routes.php:

```
return [
    'locales' => ['en', 'de']
];
```

Routing
-------

[](#routing)

Once the package is installed you can use your translation strings in route defining with square brackets.

To define group with added language prefix you can use `localeGroup` method and write all routes inside it.

```
Route::localeGroup(function() {
    Route::get('[country]/{country}', function($country) {

    });
    Route::get('[about-us]', function(){
        return 'hi!';
    });
});
```

### Named Routes

[](#named-routes)

You can also use names for your routes inside localeGroup. It will create separate route name for each locale:

```
Route::localeGroup(function(){
    Route::get('[country]/{country}', function($country){

    })->name('country')
});
```

URL Generating
--------------

[](#url-generating)

### Generate URL by route

[](#generate-url-by-route)

You can use normal `route` function to generate url in current locale:

```
route('country', ['country' => $country]);

url()->route('country', ['country' => $country])
```

Depends on current locale it will create `/en/country/...` or `/de/land/...`

You can use `routeInLocale` method if you need to generate URL in concrete locale or just add locale in your route name:

```
routeInLocale('de', 'country', ['country' => $country]);

url()->routeInLocale('de', 'country', ['country' => $country]);

route('de.country', ['country' => $country]);
```

### Generate URL by path

[](#generate-url-by-path)

You can also use translation keys in square brackets in `url` function. But it doesn't add locale prefix to your URL

```
url('[country]/belgium')

url()->to('[country]/belgium')
```

To add locale prefix to your url:

```
url()->withLocale('[country]/belgium'); // generates `en/country/belgium`

urlWithLocale('[country]/belgium');

urlWithLocale('[country]/belgium', $params, 'en'); // specify needed locale. generates `de/land/belgium`
```

Locale switch
-------------

[](#locale-switch)

To generate url for language switching you can use named route `switch-locale`

```
route('switch-locale', 'fr')
```

All static routes will be switching by default. But for routes with parameters you can add strategies and define logic for translation:

```
namespace App\Service\UrlTranslator;

use App\Models\Country;
use Ofat\LaravelTranslatableRoutes\UrlTranslator\Abstracts\BaseUrlTranslation;

class CountryUrlTranslation extends BaseUrlTranslation
{
    /**
     * Get current route translated url
     *
     * @param string $locale
     * @return string
     */
    public function getTranslatedUrl(string $locale): string
    {
        $country = Country::query()
            ->where('url->'.$this->route->getLocale(), $this->route->parameter('country'))
            ->firstOrFail();

        return $this->urlGenerator->route('country', $country->url);
    }

    /**
     * Check if current route is applicable to this strategy
     *
     * @return bool
     */
    public function isApplicable(): bool
    {
        return strpos($this->route->getName(), '.country') > 0;
    }
}
```

In this case if you try to switch language on page `/en/country/france` it will redirect to `/fr/les-pays/la-france`

In `isApplicable` method you should write your logic for checking if route is determined to your group needs.

In `getTranslatedUrl` method you should write your logic to generate url for your route on new locale

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~13 days

Total

2

Last Release

1476d ago

PHP version history (2 changes)1.0.0PHP ^7.3 || ^8.0

v1.0.1PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e6b12324ca169889adf131f4705dec3ab2aa8ba65d47f8c5f0a22dd17a31b2d4?d=identicon)[ofat](/maintainers/ofat)

---

Top Contributors

[![ofat](https://avatars.githubusercontent.com/u/1476004?v=4)](https://github.com/ofat "ofat (2 commits)")

---

Tags

laraveltranslatable

### Embed Badge

![Health badge](/badges/ofat-laravel-translatable-routes/health.svg)

```
[![Health](https://phpackages.com/badges/ofat-laravel-translatable-routes/health.svg)](https://phpackages.com/packages/ofat-laravel-translatable-routes)
```

###  Alternatives

[outl1ne/nova-translatable

A laravel-translatable extension for Laravel Nova.

203416.9k8](/packages/outl1ne-nova-translatable)[sertxudeveloper/laravel-translatable

Manage localized routes and use translatable models in a Laravel app.

183.6k](/packages/sertxudeveloper-laravel-translatable)

PHPackages © 2026

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