{"id":36406386,"url":"https://github.com/esign/laravel-underscore-translatable","last_synced_at":"2026-04-26T15:00:47.887Z","repository":{"id":56979306,"uuid":"428038390","full_name":"esign/laravel-underscore-translatable","owner":"esign","description":"A laravel package to make your eloquent models translatable.","archived":false,"fork":false,"pushed_at":"2026-04-24T13:01:38.000Z","size":31,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-04-24T15:06:03.677Z","etag":null,"topics":["i18n","laravel","php"],"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/esign.png","metadata":{"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-11-14T20:51:26.000Z","updated_at":"2026-04-24T13:01:17.000Z","dependencies_parsed_at":"2023-11-23T20:06:57.261Z","dependency_job_id":"dad79908-2c9f-4fca-b252-7481e6601875","html_url":"https://github.com/esign/laravel-underscore-translatable","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.125,"last_synced_commit":"85e4e20bc4f4282d902921fb5812ea06937489bd"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/esign/laravel-underscore-translatable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-underscore-translatable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-underscore-translatable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-underscore-translatable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-underscore-translatable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esign","download_url":"https://codeload.github.com/esign/laravel-underscore-translatable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-underscore-translatable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32301330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T09:34:17.070Z","status":"ssl_error","status_checked_at":"2026-04-26T09:34:00.993Z","response_time":129,"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":["i18n","laravel","php"],"created_at":"2026-01-11T16:42:47.345Z","updated_at":"2026-04-26T15:00:47.880Z","avatar_url":"https://github.com/esign.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Make Eloquent models translatable\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/esign/laravel-underscore-translatable.svg?style=flat-square)](https://packagist.org/packages/esign/laravel-underscore-translatable)\n[![Total Downloads](https://img.shields.io/packagist/dt/esign/laravel-underscore-translatable.svg?style=flat-square)](https://packagist.org/packages/esign/laravel-underscore-translatable)\n![GitHub Actions](https://github.com/esign/laravel-underscore-translatable/actions/workflows/main.yml/badge.svg)\n\nThis package allows you to make eloquent models translatable by using separate columns for each language, e.g. `title_nl` and `title_en`. This package is heavily inspired by Spatie's [spatie/laravel-translatable](https://github.com/spatie/laravel-translatable).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require esign/laravel-underscore-translatable\n```\n\n## Usage\n\n### Preparing your model\n\nTo make your model translatable you need to use the `Esign\\UnderscoreTranslatable\\UnderscoreTranslatable` trait on the model.\nNext up, you should define which fields are translatable by adding a public `$translatable` property.\n\n```php\nuse Esign\\UnderscoreTranslatable\\UnderscoreTranslatable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model\n{\n    use UnderscoreTranslatable;\n\n    public $translatable = ['title'];\n}\n```\n\nYour database structure should look like the following:\n```php\nSchema::create('posts', function (Blueprint $table) {\n    $table-\u003eid();\n    $table-\u003estring('title_nl')-\u003enullable();\n    $table-\u003estring('title_fr')-\u003enullable();\n    $table-\u003estring('title_en')-\u003enullable();\n});\n```\n\n### Retrieving translations\nTo retrieve a translation in the current locale you may use the attribute you have defined in the `translatable` property. Or you could use the `getTranslation` method:\n```php\n$post-\u003etitle\n$post-\u003egetTranslation('title')\n```\n\nTo retrieve a translation in a specific locale you may use the fully suffixed attribute or pass the locale to the `getTranslation` method:\n```php\n$post-\u003etitle_nl\n$post-\u003egetTranslation('title', 'nl')\n```\n\nTo retrieve all translations, you may use `getTranslations`:\n```php\n$post-\u003egetTranslations('title');\n// returns ['en' =\u003e 'Your first translation', 'nl' =\u003e 'Jouw eerste vertaling']\n```\n\nIf you omit the key, translations for all translatable attributes will be returned:\n```php\n$post-\u003egetTranslations();\n// returns ['title' =\u003e ['en' =\u003e '...', 'nl' =\u003e '...']]\n```\n\nYou may also limit the returned locales:\n```php\n$post-\u003egetTranslations('title', ['en']);\n// returns ['en' =\u003e 'Your first translation']\n```\n\nTo check if a translation exists, you may use the `hasTranslation` method:\n```php\n$post-\u003etitle_en = 'Your first translation';\n$post-\u003etitle_nl = '';\n$post-\u003etitle_fr = null;\n\n$post-\u003ehasTranslation('title', 'en'); // returns true\n$post-\u003ehasTranslation('title', 'nl'); // returns false\n$post-\u003ehasTranslation('title', 'fr'); // returns false\n```\n\nTo retrieve only the locales that have a translated column present for a specific key, use `getTranslatedLocales`:\n```php\n$post-\u003etitle_en = 'Your first translation';\n$post-\u003etitle_nl = 'Jouw eerste vertaling';\n\n$post-\u003egetTranslatedLocales('title'); // returns ['en', 'nl']\n```\n\nIn case you do not supply a locale, the current locale will be used.\n\n### Using a fallback\nThis package allows you to return the value of an attribute's `fallback_locale` defined in the `config/app.php` of your application.\n\nThe third `useFallbackLocale` parameter of the `getTranslation` method may be used to control this behaviour:\n```php\n$post-\u003etitle_en = 'Your first translation';\n$post-\u003etitle_nl = null;\n$post-\u003egetTranslation('title', 'nl', true); // returns 'Your first translation'\n$post-\u003egetTranslation('title', 'nl', false); // returns null\n```\n\nOr you may use dedicated methods for this:\n```php\n$post-\u003etitle_en = 'Your first translation';\n$post-\u003etitle_nl = null;\n$post-\u003egetTranslationWithFallback('title', 'nl'); // returns 'Your first translation'\n$post-\u003egetTranslationWithoutFallback('title', 'nl'); // returns null\n```\n\n### Setting translations\n\nTo set the translation for the current locale you may use the attribute you have defined in the `translatable` property. Or you could pass it immediately when creating a model:\n```php\n$post-\u003etitle = 'Your first translation';\n\nPost::create([\n    'title' =\u003e 'Your first translation',\n]);\n```\n\nYou may also use the `setTranslation` method:\n```php\n$post-\u003esetTranslation('title', 'en', 'Your first translation');\n$post-\u003esetTranslation('title', 'nl', 'Jouw eerste vertaling');\n```\n\nYou could also set multiple translations at once using the `setTranslations` method or immediately passing them along when creating a model:\n```php\n$post-\u003esetTranslations('title', [\n    'en' =\u003e 'Your first translation',\n    'nl' =\u003e 'Jouw eerste vertaling',\n]);\n\nPost::create([\n    'title' =\u003e [\n        'en' =\u003e 'Your first translation',\n        'nl' =\u003e 'Jouw eerste vertaling',\n    ],\n]);\n```\n\nThis package does not persist translations to the database, so don't forget to save your model:\n```php\n$post-\u003esetTranslation('title', 'en', 'Your first translation');\n$post-\u003esave();\n```\n\n### Defining accessors and mutators\nYou're able to define accessors just like you're used to in Laravel:\n```php\npublic function getTitleAttribute($value): string\n{\n    return ucfirst($value);\n}\n```\n\nThe same goes for mutators:\n```php\npublic function setTitleAttribute($value, $locale): void\n{\n    $this-\u003eattributes['title_' . $locale] = strtolower($value);\n}\n```\n\n\n## Testing\n\n```bash\ncomposer test\n```\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%2Fesign%2Flaravel-underscore-translatable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesign%2Flaravel-underscore-translatable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesign%2Flaravel-underscore-translatable/lists"}