{"id":37681790,"url":"https://github.com/dsoft/yii2-abcms-multilanguage","last_synced_at":"2026-01-16T12:26:16.936Z","repository":{"id":56939226,"uuid":"69955445","full_name":"dsoft/yii2-abcms-multilanguage","owner":"dsoft","description":"Enable multi language support in your Yii2 website.","archived":false,"fork":false,"pushed_at":"2021-06-10T13:48:22.000Z","size":57,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-21T16:44:29.758Z","etag":null,"topics":["multi-language","php","yii2"],"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/dsoft.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}},"created_at":"2016-10-04T10:38:55.000Z","updated_at":"2024-03-04T11:48:18.000Z","dependencies_parsed_at":"2022-08-21T06:50:15.262Z","dependency_job_id":null,"html_url":"https://github.com/dsoft/yii2-abcms-multilanguage","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/dsoft/yii2-abcms-multilanguage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsoft%2Fyii2-abcms-multilanguage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsoft%2Fyii2-abcms-multilanguage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsoft%2Fyii2-abcms-multilanguage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsoft%2Fyii2-abcms-multilanguage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dsoft","download_url":"https://codeload.github.com/dsoft/yii2-abcms-multilanguage/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsoft%2Fyii2-abcms-multilanguage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"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":["multi-language","php","yii2"],"created_at":"2026-01-16T12:26:16.852Z","updated_at":"2026-01-16T12:26:16.920Z","avatar_url":"https://github.com/dsoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 ABCMS Multi-Language Component\r\n\r\n## Features:\r\n* Add a language bar widget to your website\r\n* Translate models\r\n* Manage languages from database or configuration\r\n* Message translation CRUD\r\n\r\n## Install:\r\n```bash\r\ncomposer require abcms/yii2-library:dev-master\r\ncomposer require abcms/yii2-multilanguage:dev-master\r\n```\r\n\r\n## Enable multi-language support in your website:\r\n\r\n### 1. Add language and sourceLanguage attributes to your config array.\r\n```php\r\n$config = [\r\n    ......\r\n    'language' =\u003e 'en',\r\n    'sourceLanguage' =\u003e 'en',\r\n    ......\r\n];\r\n```\r\n\r\n### 2. Add multilanguage component\r\n```php\r\n[\r\n    'components' =\u003e [\r\n        ......\r\n        'multilanguage' =\u003e [\r\n            'class' =\u003e 'abcms\\multilanguage\\Multilanguage',\r\n            'languages' =\u003e [\r\n                'en' =\u003e 'English',\r\n                'ar' =\u003e 'Arabic',\r\n                'fr' =\u003e 'French',\r\n            ],\r\n        ],\r\n    ],\r\n]\r\n```\r\n\r\nAdd the component to the bootstrap array to allow it to read and set the language from cookies and URL: \r\n```php\r\n'bootstrap' =\u003e ['log', 'multilanguage'],\r\n```\r\n\r\n### 3. Add custom URL manager:\r\nThis URL manager class will automatically add the language to each URL.\r\n```php\r\n'urlManager' =\u003e [\r\n      'class' =\u003e abcms\\multilanguage\\UrlManager::className(),\r\n      'enablePrettyUrl' =\u003e true,\r\n      'showScriptName' =\u003e false,\r\n      'rules' =\u003e [\r\n          '\u003clang:([a-z]{2,3}(-[A-Z]{2})?)\u003e/\u003ccontroller\u003e/\u003caction\u003e/' =\u003e '\u003ccontroller\u003e/\u003caction\u003e',\r\n      ],\r\n],\r\n```\r\n\r\n### 4. Add a language switcher to the layout.\r\nUsing the language bar widget:\r\n```php\r\n\u003c?= abcms\\multilanguage\\widgets\\LanguageBar::widget() ?\u003e\r\n```\r\nor manually:\r\n```php\r\n\u003ca class=\"\u003c?= (Yii::$app-\u003elanguage == 'en') ? 'active' : ''; ?\u003e\" href=\"\u003c?= Url::current(['lang' =\u003e 'en']) ?\u003e\"\u003eEn\u003c/a\u003e\r\n```\r\n\r\n## Enable translation for your models and CRUDs:\r\n\r\n### 1. Migration:\r\n1- Add the migration namespaces in the console.php configuration:\r\n```php\r\n'controllerMap' =\u003e [\r\n    'migrate' =\u003e [\r\n        'class' =\u003e 'yii\\console\\controllers\\MigrateController',\r\n        'migrationNamespaces' =\u003e [\r\n            'abcms\\library\\migrations',\r\n            'abcms\\multilanguage\\migrations',\r\n        ],\r\n    ],\r\n],\r\n```\r\n\r\n2- Run `./yii migrate`\r\n\r\n\u003e You can use [abcms/yii2-generators](https://github.com/dsoft/yii2-abcms-generators) to generate a custom model and CRUD or continue with the manual steps below.\r\n\r\n### 2. Add model behavior:\r\nAdd the multi-language behavior and specify which attributes can be translated and the type for each field. If the field type is not specified, text input will be used by default.\r\n\r\n```php\r\n[\r\n    'class' =\u003e \\abcms\\multilanguage\\behaviors\\ModelBehavior::className(),\r\n    'attributes' =\u003e [\r\n        'title',\r\n        'description:text-area',\r\n    ],\r\n],\r\n```\r\n\r\n### 3. Add translation form in the admin panel:\r\nAdd in _form.php:\r\n```php\r\n\u003c?= \\abcms\\multilanguage\\widgets\\TranslationForm::widget(['model' =\u003e $model, 'form' =\u003e $form]) ?\u003e\r\n```\r\n\r\n### 4. Add translation detail view in the admin panel:\r\nAdd in view.php:\r\n```php\r\n\u003c?=\r\n\\abcms\\multilanguage\\widgets\\TranslationView::widget([\r\n    'model' =\u003e $model,\r\n])\r\n?\u003e\r\n```\r\n\r\n### 5. Enable automatic translation saving in the controller\r\nAdd in Controller create and update actions:\r\n```php\r\n$model-\u003eautomaticTranslationSaving = true;\r\n```\r\n\r\n## How to get translated content?\r\n\r\n### Get a single model translation for the current language:\r\n```php\r\n$translatedModel = $model-\u003etranslate();\r\n```\r\n\r\n### Get multiple models translation for the current language:\r\n```php\r\n$translatedModels = Yii::$app-\u003emultilanguage-\u003etranslateMultiple($models);\r\n```\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsoft%2Fyii2-abcms-multilanguage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdsoft%2Fyii2-abcms-multilanguage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsoft%2Fyii2-abcms-multilanguage/lists"}