{"id":20416414,"url":"https://github.com/folkloreinc/eloquent-localizable","last_synced_at":"2025-08-20T00:36:13.978Z","repository":{"id":18271454,"uuid":"21433316","full_name":"folkloreinc/eloquent-localizable","owner":"folkloreinc","description":"Laravel 4 and 5 package to add localization capabilities to Eloquent Models","archived":false,"fork":false,"pushed_at":"2015-07-01T16:59:36.000Z","size":286,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-27T16:48:32.114Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/folkloreinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-02T17:27:49.000Z","updated_at":"2023-10-03T12:36:35.000Z","dependencies_parsed_at":"2022-08-28T08:22:00.001Z","dependency_job_id":null,"html_url":"https://github.com/folkloreinc/eloquent-localizable","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/folkloreinc/eloquent-localizable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Feloquent-localizable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Feloquent-localizable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Feloquent-localizable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Feloquent-localizable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/folkloreinc","download_url":"https://codeload.github.com/folkloreinc/eloquent-localizable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Feloquent-localizable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271246937,"owners_count":24725901,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-15T06:19:46.723Z","updated_at":"2025-08-20T00:36:13.927Z","avatar_url":"https://github.com/folkloreinc.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eloquent Localizable\nSimple Laravel 4 and 5 package to add localization capabilities to Eloquent Models\n\n## Installation\n\n#### Dependencies:\n\n* [Laravel 5.x](https://github.com/laravel/laravel)\n\n#### Installation:\n\n**1-** Require the package with Composer\n\n```bash\n$ composer require folklore/eloquent-localizable\n```\n\n## Usage\n\n#### Configuration\nThis package use a Trait to add localization capabilities to your Eloquent modal. Basically it will add a `locales` relation to your model and provide a sync method for easy saving.\n\nFor example, if you have a `Page` model and you would like to add localized `title`, `description`. You first add the trait to your `Page` class.\n\n```php\n\nuse Folklore\\EloquentLocalizable\\LocalizableTrait;\n\nclass Page extends Eloquent {\n    \n    use LocalizableTrait;\n    \n}\n```\n\nBy default the trait will look for a `[MODEL_NAME]Locale` model. So in this example, it will looks for a `PageLocale`. Just create a `PageLocale` class next to your `Page` model.\n\n```php\n\nuse Folklore\\EloquentLocalizable\\LocaleModel;\n\nclass PageLocale extends LocaleModel {\n    \n    protected $table = 'pages_locales';\n    \n}\n```\n\nYou can change the locale model class by overiding the `getLocaleModelClass` method.\n\n```php\n\nuse Folklore\\EloquentLocalizable\\LocalizableTrait;\n\nclass Page extends Eloquent {\n    \n    use LocalizableTrait;\n    \n    protected function getLocaleModelClass()\n    {\n        return 'App\\Models\\CustomLocaleModel';\n    }\n    \n}\n```\n\nYou also need to create the table for you localization. Following the example, we will create a migration for a `pages_locales` table.\n\n```php\nSchema::create('pages_locales', function(Blueprint $table)\n{\n\t$table-\u003eincrements('id');\n\t$table-\u003einteger('page_id')-\u003eunsigned();\n\t$table-\u003estring('locale',2);\n\t$table-\u003estring('title');\n\t$table-\u003estring('description');\n\t$table-\u003etimestamps();\n\t\n\t$table-\u003eindex('page_id');\n\t$table-\u003eindex('locale');\n});\n```\n\n#### Getting locales\nYou can now use the locales relation on your `Page` model.\n\nGetting a page with all locales\n```php\n$page = Page::with('locales')-\u003efirst();\n\n//Getting the title for a specific locale\necho $page-\u003elocales-\u003efr-\u003etitle;\n\n//Looping through all locales\nforeach($page-\u003elocales as $locale)\n{\n    echo $locale-\u003elocale.': '.$locale-\u003etitle;\n}\n```\n\nGetting a page with a specific locale\n```php\n$page = Page::withLocale('fr')-\u003efirst();\n\n//Getting a the title\necho $page-\u003elocale-\u003efr-\u003etitle;\n```\n\nIf you want to always include the locales when fetching a page.\n```php\n\nuse Folklore\\EloquentLocalizable\\LocalizableTrait;\n\nclass Page extends Eloquent {\n    \n    use LocalizableTrait;\n    \n    protected $with = ['locales'];\n    \n}\n```\n\n#### Saving locales\nYou can use the `syncLocales` method to save your locales.\n\n```php\n$locales = array(\n    'en' =\u003e array(\n        'title' =\u003e 'A page',\n        'description' =\u003e 'This is the description of this page'\n    ),\n    'fr' =\u003e array(\n        'title' =\u003e 'Une page',\n        'description' =\u003e 'Ceci est la description de cette page'\n    )\n);\n\n//or\n\n$locales = array(\n    array(\n        'locale' =\u003e 'en',\n        'title' =\u003e 'A page',\n        'description' =\u003e 'This is the description of this page'\n    ),\n    array(\n        'locale' =\u003e 'fr',\n        'title' =\u003e 'Une page',\n        'description' =\u003e 'Ceci est la description de cette page'\n    )\n);\n\n$page = new Page();\n$page-\u003esave(); //We need an id for this page, so we save before.\n\n$page-\u003esyncLocales($locales);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolkloreinc%2Feloquent-localizable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffolkloreinc%2Feloquent-localizable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolkloreinc%2Feloquent-localizable/lists"}