{"id":15672686,"url":"https://github.com/yiimaker/yii2-translatable","last_synced_at":"2025-05-06T21:44:36.393Z","repository":{"id":57087211,"uuid":"126732977","full_name":"yiimaker/yii2-translatable","owner":"yiimaker","description":"Translatable behavior aggregates logic of linking translations to the primary model","archived":false,"fork":false,"pushed_at":"2022-06-29T18:39:52.000Z","size":80,"stargazers_count":15,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T10:56:39.695Z","etag":null,"topics":["i18n","translatable","translations","yii2","yii2-behaviors","yii2-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiimaker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-25T19:35:47.000Z","updated_at":"2022-06-29T12:07:28.000Z","dependencies_parsed_at":"2022-08-24T22:50:52.714Z","dependency_job_id":null,"html_url":"https://github.com/yiimaker/yii2-translatable","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiimaker%2Fyii2-translatable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiimaker%2Fyii2-translatable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiimaker%2Fyii2-translatable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiimaker%2Fyii2-translatable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiimaker","download_url":"https://codeload.github.com/yiimaker/yii2-translatable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776413,"owners_count":21802459,"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":["i18n","translatable","translations","yii2","yii2-behaviors","yii2-extension"],"created_at":"2024-10-03T15:30:10.354Z","updated_at":"2025-05-06T21:44:36.363Z","avatar_url":"https://github.com/yiimaker.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/OCmHjEY"],"categories":[],"sub_categories":[],"readme":"[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://stand-with-ukraine.pp.ua)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiimaker\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://avatars1.githubusercontent.com/u/24204902\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eTranslatable behavior\u003c/h1\u003e\n\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/yiimaker/yii2-translatable.svg?branch=master)](https://travis-ci.org/yiimaker/yii2-translatable)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiimaker/yii2-translatable/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiimaker/yii2-translatable/?branch=master)\n[![Total Downloads](https://img.shields.io/packagist/dt/yiimaker/yii2-translatable.svg)](https://packagist.org/packages/yiimaker/yii2-translatable)\n[![Latest Stable Version](https://img.shields.io/packagist/v/yiimaker/yii2-translatable.svg)](https://packagist.org/packages/yiimaker/yii2-translatable)\n[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)\n\nTranslatable behavior aggregates logic of linking translations to the primary model.\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\n$ composer require yiimaker/yii2-translatable\n```\n\nor add\n\n```\n\"yiimaker/yii2-translatable\": \"~1.0\"\n```\n\nto the `require` section of your `composer.json`.\n\nUsage\n-----\n\n1. Add behavior to the your primary model\n\n```php\npublic function behaviors()\n{\n    return [\n        // ...\n        'translatable' =\u003e [\n            'class' =\u003e TranslatableBehavior::className(),\n            // 'translationRelationName' =\u003e 'translations',\n            // 'translationLanguageAttrName' =\u003e 'language',\n            // 'attributeNamePattern' =\u003e '%name% [%language%]',\n            'translationAttributeList' =\u003e [\n                'title',\n                'description',\n            ],\n        ],\n    ];\n}\n```\n\n2. And use `getTranslation()` or `translateTo()` methods\n\n```php\n// product is an active record model with translatable behavior\n$product = new Product();\n\n// sets translation for default application language\n$product-\u003etitle = 'PhpStrom 2018.1';\n$product-\u003edescription = 'Лицензия PhpStrom IDE версия 2018.1';\n\n// gets translation for English language\n$translation = $product-\u003egetTranslation('en');\n$translation-\u003etitle = 'PhpStrom 2018.1';\n$translation-\u003edescription = 'License of the PhpStrom IDE version 2018.1';\n\n// sets description for French language\n$product-\u003etranslateTo('fr')-\u003edescription = 'La licence de PhpStorm IDE la version 2018.1';\n\n$product-\u003einsert();\n```\n\n`translateTo()` it's just an alias for `getTranslation()` method.\n\nAfter saving the model you can fetch this model from the database and translatable behavior will fetch all translations automatically.\n\n```php\n$product = Product::find()\n    -\u003ewhere(['id' =\u003e 1])\n    -\u003ewith('translations')\n    -\u003eone()\n;\n\n// gets translation for English language\n$product-\u003etranslateTo('en')-\u003edescription; // License of the PhpStrom IDE version 2018.1\n// gets translation for French language\n$product-\u003etranslateTo('fr')-\u003edescription; // La licence de PhpStorm IDE la version 2018.1\n\n// check whether Ukrainian translation not exists\nif (!$product-\u003ehasTranslation('uk')) {\n    $product-\u003etranslateTo('uk')-\u003edescription = 'Ліцензія PhpStrom IDE версія 2018.1';\n}\n\n// update Enlish translation\n$product-\u003etranslateTo('en')-\u003etitle = 'PhpStorm IDE';\n\n$product-\u003eupdate();\n```\n\nTests\n-----\n\nYou can run tests with composer command\n\n```\n$ composer test\n```\n\nor using following command\n\n```\n$ codecept build \u0026\u0026 codecept run\n```\n\nContributing\n------------\n\nFor information about contributing please read [CONTRIBUTING.md](CONTRIBUTING.md).\n\nSponsoring\n----------\n\n\u003ca href=\"https://www.buymeacoffee.com/OCmHjEY\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n\nLicense\n-------\n\n[![License](https://img.shields.io/github/license/yiimaker/yii2-translatable.svg)](LICENSE)\n\nThis project is released under the terms of the BSD-3-Clause [license](LICENSE).\n\nCopyright (c) 2017-2022, Yii Maker\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiimaker%2Fyii2-translatable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiimaker%2Fyii2-translatable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiimaker%2Fyii2-translatable/lists"}