{"id":20812184,"url":"https://github.com/sertxudeveloper/laravel-translatable","last_synced_at":"2025-07-17T21:39:18.895Z","repository":{"id":46283155,"uuid":"206405063","full_name":"sertxudeveloper/laravel-translatable","owner":"sertxudeveloper","description":"Manage localized routes and use translatable models in a Laravel app.","archived":false,"fork":false,"pushed_at":"2024-10-07T02:59:40.000Z","size":477,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T03:58:27.645Z","etag":null,"topics":["eloquent-translations","hacktoberfest","language","laravel","laravel-translatable","localization","sertxudeveloper","translatable-models","translation","translations","translations-tables"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sertxudeveloper.png","metadata":{"funding":{"github":["sertxudev"],"custom":["https://buymeacoffee.com/sertxudeveloper"]},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-04T20:12:48.000Z","updated_at":"2024-08-03T11:13:24.000Z","dependencies_parsed_at":"2022-09-22T19:10:51.226Z","dependency_job_id":"a6819e75-3cb7-4642-bf21-494406edb485","html_url":"https://github.com/sertxudeveloper/laravel-translatable","commit_stats":{"total_commits":80,"total_committers":2,"mean_commits":40.0,"dds":"0.012499999999999956","last_synced_commit":"52016c29e8b593d1eb3e08b91857059fef5499a5"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/sertxudeveloper/laravel-translatable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sertxudeveloper%2Flaravel-translatable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sertxudeveloper%2Flaravel-translatable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sertxudeveloper%2Flaravel-translatable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sertxudeveloper%2Flaravel-translatable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sertxudeveloper","download_url":"https://codeload.github.com/sertxudeveloper/laravel-translatable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sertxudeveloper%2Flaravel-translatable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265663409,"owners_count":23807467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent-translations","hacktoberfest","language","laravel","laravel-translatable","localization","sertxudeveloper","translatable-models","translation","translations","translations-tables"],"created_at":"2024-11-17T20:51:06.086Z","updated_at":"2025-07-17T21:39:18.875Z","avatar_url":"https://github.com/sertxudeveloper.png","language":"PHP","funding_links":["https://github.com/sponsors/sertxudev","https://buymeacoffee.com/sertxudeveloper"],"categories":[],"sub_categories":[],"readme":"\n\u003cp align=\"center\"\u003e\u003cimg src=\"/art/socialcard.png\" alt=\"Laravel Translatable by Sertxu Developer\"\u003e\u003c/p\u003e\n\n# Laravel Translatable\n\n![](https://img.shields.io/github/v/release/sertxudeveloper/laravel-translatable) ![](https://img.shields.io/github/license/sertxudeveloper/laravel-translatable) ![](https://img.shields.io/librariesio/github/sertxudeveloper/laravel-translatable) ![](https://img.shields.io/github/repo-size/sertxudeveloper/laravel-translatable) ![](https://img.shields.io/packagist/dt/sertxudeveloper/laravel-translatable) ![](https://img.shields.io/github/issues/sertxudeveloper/laravel-translatable) ![](https://img.shields.io/packagist/php-v/sertxudeveloper/laravel-translatable)\n\n**Manage localized routes and use translatable models in a Laravel app.**\n - Automatically register the routes for each locale you wish to support.\n - Optionally remove the locale slug from the URL for your main language.\n - Generate localized route URLs using the `trans_route()` helper.\n - Allow routes to be cached.\n\n## Requirements\n  - PHP \u003e= 7.4\n  - Laravel \u003e= 8.x\n\n## Installation\nYou can install this package using Composer.\n\n```sh\ncomposer require sertxudeveloper/laravel-translatable\n```\n\n## Configuration\nFirst you should publish the configuration file.\n\n```sh\nphp artisan vendor:publish --tag='trans-config'\n```\n\nAfter running this command, you will now find a `translatable.php`` file in the `config` folder.\n\n### Locales available\nYou can set the locales availables in your application. The localized routes will be registered with all of these locales.\n\n```php\n'locales' =\u003e ['es', 'en', 'it'],\n```\n### Fallback locale\nThe fallback locale should be the one that not require to be translated.\n\n```php\n'fallback_locale' =\u003e 'es',\n```\nYou can also hide the fallback locale from the URL prefix.\n\n```php\n\"hide_fallback_locale\" =\u003e true,\n```\n\n# Routes\n## Register Routes\nAll the routes you want lo localize should be registered inside the `Route::localized` closure.\n\n```php\n// Not Localized\nRoute::get('home', [HomeController::class, 'index'])-\u003ename('home');\n\n// Localized\nRoute::localized(function () {\n  Route::get('blog', [BlogController::class, 'index'])-\u003ename('blog')\n  Route::get('{slug}', [PageController::class, 'index'])-\u003ename('page')\n});\n\n// Not Localized\nRoute::get('about', [AboutController::class, 'index'])-\u003ename('about');\n```\n\nInside 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.\n\nThis will be the result of the viewed configuration examples.\n\n| URI | Name | Locale |\n| --- | --- | --- |\n| /home | home | es - en - it |\n| --- | --- | --- |\n| /blog | blog | es |\n| /es/blog | es.blog | es |\n| /en/blog | en.blog | en |\n| /it/blog | it.blog | it |\n| --- | --- | --- |\n| /{slug} | page | es |\n| /es/{slug} | es.page | es |\n| /en/{slug} | en.page | en |\n| /it/{slug} | it.page | it |\n| --- | --- | --- |\n| /about | about | es - en - it |\n\n\u003e 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.\n\n## Generate Localized URLs\nYou 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.\n\n```php\ntrans_route($name, $parameters = [], $absolute = false, $locale = null)\n```\n\nIf you pass only the route it will be localized using the current locale (`'en'`).\n\n```php\ntrans_route('blog') // /en/blog\n```\n\nYou can also pass params to the helper.\n\n```php\ntrans_route('page', ['help']) // /en/help\n```\n\nThe third param is a boolean to make it absolute or not.\n\n```php\ntrans_route('page', ['help'], true) // https://yourdomain.test/en/help\n```\n\n```php\ntrans_route('page', ['help'], false) // /en/help\n```\n\nThe last param is used for specify the locale to use.\n\n```php\ntrans_route('blog', [], false, 'it') // /it/blog\n```\n\n## Switch Locale\nIf you're building a dropdown or similar with links to change the locale of the application, you should use the `switch_to_locale` helper.\n```php\nswitch_to_locale('en') // Changes to 'en' locale without changing the route\n```\n\n# Eloquent translations\n\n## Create translations tables\nYou can to customize the name of the translations tables.\n\n```php\n'table_suffix' =\u003e '_translations'\n```\n\nThe 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`.\nThis 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.\n\nThe 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`.\nThe column `deleted_at` should **never** be in the translations table, regardless the models is `softDeleted` or not.\n\nAs you can see in the following example,\n\n#### Pages table\n| id | name | slug | excerpt | body | image | status | created_at | updated_at |\n| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n| int | varchar | varchar | varchar | text | varchar | enum | datetime | datetime |\n\n#### Pages translation table\n| id | locale | name | excerpt | body | created_at | updated_at |\n| --- | --- | --- | --- | --- | --- | --- |\n| int | varchar(2) | varchar | varchar | text | datetime | datetime |\n\n## Get Eloquent Translated Attribute\nIn order to get a translated attribute you should use the ``getTranslated`` method.\n\n```php\n$post = Post::find(1);\necho $post-\u003egetTranslated('name');\n```\n\n## Cache Routes\nIn production, you can safely cache your routes per usual.\n\n```sh\nphp artisan route:cache\n```\n\n\u003cbr\u003e\u003cbr\u003e\n\u003cp align=\"center\"\u003eCopyright © 2022 Sertxu Developer\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsertxudeveloper%2Flaravel-translatable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsertxudeveloper%2Flaravel-translatable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsertxudeveloper%2Flaravel-translatable/lists"}