{"id":36334312,"url":"https://github.com/jetcod/laravel-model-translation","last_synced_at":"2026-01-11T12:03:55.255Z","repository":{"id":246692374,"uuid":"821384642","full_name":"jetcod/laravel-model-translation","owner":"jetcod","description":"Laravel Translation simplifies managing model attribute translations in your Laravel applications.","archived":false,"fork":false,"pushed_at":"2024-10-23T08:48:47.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-23T12:12:43.082Z","etag":null,"topics":["laravel","laravel-translation","localization"],"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/jetcod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-06-28T12:22:49.000Z","updated_at":"2024-10-23T08:48:51.000Z","dependencies_parsed_at":"2024-10-23T05:06:17.046Z","dependency_job_id":null,"html_url":"https://github.com/jetcod/laravel-model-translation","commit_stats":null,"previous_names":["jetcod/laravel-translation","jetcod/laravel-model-translation"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jetcod/laravel-model-translation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetcod%2Flaravel-model-translation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetcod%2Flaravel-model-translation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetcod%2Flaravel-model-translation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetcod%2Flaravel-model-translation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jetcod","download_url":"https://codeload.github.com/jetcod/laravel-model-translation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetcod%2Flaravel-model-translation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28302150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["laravel","laravel-translation","localization"],"created_at":"2026-01-11T12:03:54.665Z","updated_at":"2026-01-11T12:03:55.249Z","avatar_url":"https://github.com/jetcod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Model Translation\n\n[![Actions Status](https://github.com/jetcod/laravel-model-translation/actions/workflows/tests.yml/badge.svg?style=for-the-badge\u0026label=%3Cb%3EBuild%3C/b%3E)](https://github.com/jetcod/laravel-model-translation/actions)\n\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/jetcod/laravel-model-translation?label=Latest%20Stable%20Version)](https://packagist.org/packages/jetcod/laravel-model-translation)\n[![Total Downloads](https://img.shields.io/packagist/dt/jetcod/laravel-model-translation?label=Total%20Downloads)](https://packagist.org/packages/jetcod/laravel-model-translation)\n[![License](https://img.shields.io/github/license/jetcod/laravel-model-translation?label=License)](https://github.com/jetcod/eloquent-repository/blob/main/LICENSE)\n\nLaravel Translation is a package that provides a simple and efficient way to manage translations in your Laravel applications. It allows you to store translations of all your models attributes in database, making it easy to manage and update translations without modifying language files.\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require jetcod/laravel-model-translation\n```\n\n## Configuration\nAfter installing the package, you need to publish the configuration file and migration:\n\n```bash\nphp artisan vendor:publish --tag=translation-config\nphp artisan vendor:publish --tag=translation-migrations\n```\n\nThen, run the migration to create the translations table:\n\n```bash\nphp artisan migrate\n```\n\nIn order to avoid conflictig with other packages and database tables, you can customize your database table name in the `config/translation.php` config file:\n\n```php\nreturn [\n    'database' =\u003e [\n        'prefix' =\u003e env('TRANSLATION_TABLE_PREFIX', 'lt_'),\n        'table_name' =\u003e env('TRANSLATION_TABLE_NAME', 'translations'),\n    ],\n];\n```\n\n## Usage\n\n### Setup model\nFirst, you need to import the `Jetcode\\Laravel\\Translation\\Traits\\HasTranslations` trait in your model and specify the fields you want to translate:\n\n```php\nuse Jetcode\\Laravel\\Translation\\Traits\\HasTranslations;\n\nclass Post extends Model\n{\n    use HasTranslations;\n\n    protected const TRANSLATABLE_ATTRIBUTES = ['title', 'content'];\n}\n```\nAlternatively, you can specify the fields in a method in your model class:\n\n```php\nuse Jetcode\\Laravel\\Translation\\Traits\\HasTranslations;\n\nclass Post extends Model\n{\n    use HasTranslations;\n\n    protected function getTranslatableAttributes()\n    {\n        return ['title', 'content'];\n    }\n}\n```\n\n\u003e **NOTE**: The `TRANSLATABLE_ATTRIBUTES` constant or the `getTranslatableAttributes` method return value can be either a string or an array of the model attribute names.\n\n**Defining translatable attributes is optional, but it is recommended to define them.**\n\n### Create a translation\nNow, you can create translations for the model attributes through the defined relations:\n\n```php\n// Create a new post with translations\n$post = Post::create([\n    'title' =\u003e 'Hello World',\n    'content' =\u003e 'This is a post',\n]);\n\n// Create a new translation for the post\n$post-\u003etranslation()-\u003esaveMany([\n    new Translation([\n        'locale' =\u003e 'fr_FR',\n        'key'    =\u003e 'title',\n        'value'  =\u003e 'Bonjour le monde',\n    ]),\n    new Translation([\n        'locale' =\u003e 'fr_FR',\n        'key'    =\u003e 'content',\n        'value'  =\u003e 'Ceci est un article',\n    ]),\n]);\n```\n\n### Retrieve translated model\nThis package is compatible with Laravel localization system, so the models are translated according to the current locale. All you need to do is to set the appl locale and your model will be translated automatically:\n\n```php\n$post = Post::find(123);\nvar_dump($post-\u003etitle);     // \"Hello World\"\n\napp()-\u003esetLocale('fr_FR');\nvar_dump($post-\u003etitle);     // \"Bonjour le monde\"\n```\n\nAlternatively, you can use the `withLocale` method to retrieve the translated model for  a specific locale:\n\n```php\nvar_dump($post-\u003ewithLocale('fr_FR')-\u003etitle); // \"Bonjour le monde\"\n\n// Current locale is reset to default afterwards\nvar_dump($post-\u003etitle); // \"Hello World\"\n```\n\n## Testing\nThe package includes tests that you can run using `PHPUnit`:\n\n```bash\ncomposer test\n```\n\nYou can also run static analysis with PHPStan:\n\n```bash\ncomposer phpstan\n```\n\n## License\nThis package is open-source software licensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetcod%2Flaravel-model-translation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjetcod%2Flaravel-model-translation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetcod%2Flaravel-model-translation/lists"}