{"id":13396276,"url":"https://github.com/spatie/laravel-translatable","last_synced_at":"2025-05-14T22:02:25.910Z","repository":{"id":40380683,"uuid":"55690447","full_name":"spatie/laravel-translatable","owner":"spatie","description":"Making Eloquent models translatable","archived":false,"fork":false,"pushed_at":"2025-04-22T07:32:20.000Z","size":328,"stargazers_count":2326,"open_issues_count":1,"forks_count":287,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-05-05T22:03:51.775Z","etag":null,"topics":["eloquent","i18n","laravel","php","translated-attributes"],"latest_commit_sha":null,"homepage":"https://spatie.be/docs/laravel-translatable","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/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/support-us.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"spatie"}},"created_at":"2016-04-07T11:49:51.000Z","updated_at":"2025-05-05T10:18:20.000Z","dependencies_parsed_at":"2024-03-25T05:26:23.525Z","dependency_job_id":"f17aa558-1268-4dce-8b57-6e38bc184961","html_url":"https://github.com/spatie/laravel-translatable","commit_stats":{"total_commits":275,"total_committers":71,"mean_commits":"3.8732394366197185","dds":"0.46545454545454545","last_synced_commit":"6221015867f7f1b1736310ea480c35886fb8036b"},"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translatable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translatable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translatable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-translatable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-translatable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252793664,"owners_count":21805057,"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","i18n","laravel","php","translated-attributes"],"created_at":"2024-07-30T18:00:43.641Z","updated_at":"2025-05-07T08:23:37.283Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":["Popular Packages","Paquetes utiles","PHP","Plugins"],"sub_categories":["Integrations \u0026 API"],"readme":"\u003cdiv align=\"left\"\u003e\n    \u003ca href=\"https://spatie.be/open-source?utm_source=github\u0026utm_medium=banner\u0026utm_campaign=laravel-translatable\"\u003e\n      \u003cpicture\u003e\n        \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://spatie.be/packages/header/laravel-translatable/html/dark.webp\"\u003e\n        \u003cimg alt=\"Logo for laravel-translatable\" src=\"https://spatie.be/packages/header/laravel-translatable/html/light.webp\" height=\"190\"\u003e\n      \u003c/picture\u003e\n    \u003c/a\u003e\n\n\u003ch1\u003eA trait to make Eloquent models translatable\u003c/h1\u003e\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-translatable)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-translatable/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-translatable)\n    \n\u003c/div\u003e\n\nThis package contains a trait `HasTranslations` to make Eloquent models translatable. Translations are stored as json. There is no extra table needed to hold them.\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Spatie\\Translatable\\HasTranslations;\n\nclass NewsItem extends Model\n{\n    use HasTranslations;\n    \n    public $translatable = ['name']; // translatable attributes\n\n    // ...\n}\n```\n\nAfter the trait is applied on the model you can do these things:\n\n```php\n$newsItem = new NewsItem;\n$newsItem\n   -\u003esetTranslation('name', 'en', 'Name in English')\n   -\u003esetTranslation('name', 'nl', 'Naam in het Nederlands')\n   -\u003esave();\n\n$newsItem-\u003ename; // Returns 'Name in English' given that the current app locale is 'en'\n$newsItem-\u003egetTranslation('name', 'nl'); // returns 'Naam in het Nederlands'\n\napp()-\u003esetLocale('nl');\n$newsItem-\u003ename; // Returns 'Naam in het Nederlands'\n\n$newsItem-\u003egetTranslations('name'); // returns an array of all name translations\n\n// You can translate nested keys of a JSON column using the -\u003e notation\n// First, add the path to the $translatable array, e.g., 'meta-\u003edescription'\n$newsItem\n   -\u003esetTranslation('meta-\u003edescription', 'en', 'Description in English')\n   -\u003esetTranslation('meta-\u003edescription', 'nl', 'Beschrijving in het Nederlands')\n   -\u003esave();\n\n$attributeKey = 'meta-\u003edescription';\n$newsItem-\u003e$attributeKey; // Returns 'Description in English'\n$newsItem-\u003egetTranslation('meta-\u003edescription', 'nl'); // Returns 'Beschrijving in het Nederlands'\n```\n\nAlso providing scoped queries for retrieving records based on locales\n\n```php\n// Returns all news items with a name in English\nNewsItem::whereLocale('name', 'en')-\u003eget();\n\n// Returns all news items with a name in English or Dutch\nNewsItem::whereLocales('name', ['en', 'nl'])-\u003eget();\n\n// Returns all news items that has name in English with value `Name in English` \nNewsItem::query()-\u003ewhereJsonContainsLocale('name', 'en', 'Name in English')-\u003eget();\n\n// Returns all news items that has name in English or Dutch with value `Name in English` \nNewsItem::query()-\u003ewhereJsonContainsLocales('name', ['en', 'nl'], 'Name in English')-\u003eget();\n\n// The last argument is the \"operand\" which you can tweak to achieve something like this:\n\n// Returns all news items that has name in English with value like `Name in...` \nNewsItem::query()-\u003ewhereJsonContainsLocale('name', 'en', 'Name in%', 'like')-\u003eget();\n\n// Returns all news items that has name in English or Dutch with value like `Name in...` \nNewsItem::query()-\u003ewhereJsonContainsLocales('name', ['en', 'nl'], 'Name in%', 'like')-\u003eget();\n```\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-translatable.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-translatable)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Documentation\n\nAll documentation is available [on our documentation site](https://spatie.be/docs/laravel-translatable).\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [Sebastian De Deyne](https://github.com/sebastiandedeyne)\n- [All Contributors](../../contributors)\n\nWe got the idea to store translations as json in a column from [Mohamed Said](https://github.com/themsaid). Parts of the readme of [his multilingual package](https://github.com/themsaid/laravel-multilingual) were used in this readme.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-translatable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-translatable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-translatable/lists"}