PHPackages                             sertxudeveloper/laravel-translatable - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. sertxudeveloper/laravel-translatable

ActiveLibrary[Localization &amp; i18n](/categories/localization)

sertxudeveloper/laravel-translatable
====================================

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

v2.0.1(1y ago)183.6k2[1 PRs](https://github.com/sertxudeveloper/laravel-translatable/pulls)MITPHPPHP ^8.1|^8.2

Since Sep 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/sertxudeveloper/laravel-translatable)[ Packagist](https://packagist.org/packages/sertxudeveloper/laravel-translatable)[ Docs](https://github.com/sertxudeveloper/laravel-translatable)[ Fund](https://buymeacoffee.com/sertxudeveloper)[ GitHub Sponsors](https://github.com/sertxudev)[ RSS](/packages/sertxudeveloper-laravel-translatable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (18)Used By (0)

[![Laravel Translatable by Sertxu Developer](/art/socialcard.png)](/art/socialcard.png)

Laravel Translatable
====================

[](#laravel-translatable)

[![](https://camo.githubusercontent.com/0e8e7197ba87f693bb7fdc465e50f526c2084f678b8833caf357a59cf2a91077/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)](https://camo.githubusercontent.com/0e8e7197ba87f693bb7fdc465e50f526c2084f678b8833caf357a59cf2a91077/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65) [![](https://camo.githubusercontent.com/33f5895895b1c11b4b5ca661e02118752f9aa7fef0159792f895d0fbd2549dc9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)](https://camo.githubusercontent.com/33f5895895b1c11b4b5ca661e02118752f9aa7fef0159792f895d0fbd2549dc9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65) [![](https://camo.githubusercontent.com/e257f38a584a383624357f03d61d529a7ade7d43bdfc5deb56beb9ef349de972/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)](https://camo.githubusercontent.com/e257f38a584a383624357f03d61d529a7ade7d43bdfc5deb56beb9ef349de972/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65) [![](https://camo.githubusercontent.com/805a3f8b4591d355e004e116b9d46e724e195178c5944d1f71faaa9d266732ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)](https://camo.githubusercontent.com/805a3f8b4591d355e004e116b9d46e724e195178c5944d1f71faaa9d266732ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65) [![](https://camo.githubusercontent.com/079da9276278402fd970207103b31dfa349dc534252edd98daf47a2263ab4706/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)](https://camo.githubusercontent.com/079da9276278402fd970207103b31dfa349dc534252edd98daf47a2263ab4706/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65) [![](https://camo.githubusercontent.com/668e59e51e08710c148aad9f3723a87350e8c6cd25ccacd702027ca9aed3cbd1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)](https://camo.githubusercontent.com/668e59e51e08710c148aad9f3723a87350e8c6cd25ccacd702027ca9aed3cbd1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65) [![](https://camo.githubusercontent.com/a8d32b2e149771eff18328273714f73d9fc9308940f931a8f59ede09cb51461f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)](https://camo.githubusercontent.com/a8d32b2e149771eff18328273714f73d9fc9308940f931a8f59ede09cb51461f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736572747875646576656c6f7065722f6c61726176656c2d7472616e736c617461626c65)

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

- Automatically register the routes for each locale you wish to support.
- Optionally remove the locale slug from the URL for your main language.
- Generate localized route URLs using the `trans_route()` helper.
- Allow routes to be cached.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- Laravel &gt;= 8.x

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

[](#installation)

You can install this package using Composer.

```
composer require sertxudeveloper/laravel-translatable
```

Configuration
-------------

[](#configuration)

First you should publish the configuration file.

```
php artisan vendor:publish --tag='trans-config'
```

After running this command, you will now find a `translatable.php`` file in the `config` folder.

### Locales available

[](#locales-available)

You can set the locales availables in your application. The localized routes will be registered with all of these locales.

```
'locales' => ['es', 'en', 'it'],
```

### Fallback locale

[](#fallback-locale)

The fallback locale should be the one that not require to be translated.

```
'fallback_locale' => 'es',
```

You can also hide the fallback locale from the URL prefix.

```
"hide_fallback_locale" => true,
```

Routes
======

[](#routes)

Register Routes
---------------

[](#register-routes)

All the routes you want lo localize should be registered inside the `Route::localized` closure.

```
// Not Localized
Route::get('home', [HomeController::class, 'index'])->name('home');

// Localized
Route::localized(function () {
  Route::get('blog', [BlogController::class, 'index'])->name('blog')
  Route::get('{slug}', [PageController::class, 'index'])->name('page')
});

// Not Localized
Route::get('about', [AboutController::class, 'index'])->name('about');
```

Inside this closure you can use Route Groups such as Middlewares, Namespaces or even Sub-Domain Routing. This closure will prepend the locale to the route's URI and name.

This will be the result of the viewed configuration examples.

URINameLocale/homehomees - en - it---------/blogbloges/es/bloges.bloges/en/blogen.blogen/it/blogit.blogit---------/{slug}pagees/es/{slug}es.pagees/en/{slug}en.pageen/it/{slug}it.pageit---------/aboutaboutes - en - it> Beware that you don't register the same URL twice when omitting the locale. You can't have a localized /about route and also register a non-localized /about route in this case. The same idea applies to the / (root) route! Also note that the route names still have the locale prefix.

Generate Localized URLs
-----------------------

[](#generate-localized-urls)

You should use the `trans_route` helper in order to get the requested route localized. To this helper you can pass a route name or a route url, in booth cases it will be localized.

```
trans_route($name, $parameters = [], $absolute = false, $locale = null)
```

If you pass only the route it will be localized using the current locale (`'en'`).

```
trans_route('blog') // /en/blog
```

You can also pass params to the helper.

```
trans_route('page', ['help']) // /en/help
```

The third param is a boolean to make it absolute or not.

```
trans_route('page', ['help'], true) // https://yourdomain.test/en/help
```

```
trans_route('page', ['help'], false) // /en/help
```

The last param is used for specify the locale to use.

```
trans_route('blog', [], false, 'it') // /it/blog
```

Switch Locale
-------------

[](#switch-locale)

If you're building a dropdown or similar with links to change the locale of the application, you should use the `switch_to_locale` helper.

```
switch_to_locale('en') // Changes to 'en' locale without changing the route
```

Eloquent translations
=====================

[](#eloquent-translations)

Create translations tables
--------------------------

[](#create-translations-tables)

You can to customize the name of the translations tables.

```
'table_suffix' => '_translations'
```

The usage of this value will be the following one. If you have the model `Page` with the trait `HasTranslations` and the model table is `pages`. This package will look up for the translations at the table `page_translations`. Always the model table followed by the table suffix in the config file.

The translations tables should contain the translatable fields from the model, the id, a column `locale` to specify the language saved, `created_at` and `updated_at`. The column `deleted_at` should **never** be in the translations table, regardless the models is `softDeleted` or not.

As you can see in the following example,

#### Pages table

[](#pages-table)

idnameslugexcerptbodyimagestatuscreated\_atupdated\_atintvarcharvarcharvarchartextvarcharenumdatetimedatetime#### Pages translation table

[](#pages-translation-table)

idlocalenameexcerptbodycreated\_atupdated\_atintvarchar(2)varcharvarchartextdatetimedatetimeGet Eloquent Translated Attribute
---------------------------------

[](#get-eloquent-translated-attribute)

In order to get a translated attribute you should use the `getTranslated` method.

```
$post = Post::find(1);
echo $post->getTranslated('name');
```

Cache Routes
------------

[](#cache-routes)

In production, you can safely cache your routes per usual.

```
php artisan route:cache
```

Copyright © 2022 Sertxu Developer

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% 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 ~128 days

Recently: every ~134 days

Total

15

Last Release

647d ago

Major Versions

v1.10.0 → v2.0.02024-03-11

PHP version history (4 changes)1.0PHP ^7.1

1.4.0PHP ^7.1|^8.0

1.6.0PHP ^7.4|^8.0

v2.0.0PHP ^8.1|^8.2

### Community

Maintainers

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

---

Top Contributors

[![sertxudev](https://avatars.githubusercontent.com/u/22801379?v=4)](https://github.com/sertxudev "sertxudev (94 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

eloquent-translationshacktoberfestlanguagelaravellaravel-translatablelocalizationsertxudevelopertranslatable-modelstranslationtranslationstranslations-tableslaravellocalizationtranslatable

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/packages/kkomelin-laravel-translatable-string-exporter)[outhebox/laravel-translations

Manage your Laravel translations with a beautiful UI. Add, edit, delete, import, and export translations with ease.

80687.6k](/packages/outhebox-laravel-translations)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5514.4k1](/packages/longman-laravel-multilang)

PHPackages © 2026

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