The translateable behavior for the Yii framework.
The translateable behavior for the Yii framework.
A modern translateable behavior for the Yii framework.
The preferred way to install this extension is through composer.
Either run
$ composer require creocoder/yii2-translateableor add
"creocoder/yii2-translateable": "~1.0"to the require section of your composer.json file.
Run the following command
$ yii migrate/create create_post_tableOpen the /path/to/migrations/m_xxxxxx_xxxxxx_create_post_table.php file,
inside the up() method add the following
$this->createTable('{{%post}}', [
'id' => Schema::TYPE_PK,
]);Run the following command
$ yii migrate/create create_post_translation_tableOpen the /path/to/migrations/m_xxxxxx_xxxxxx_create_post_translation_table.php file,
inside the up() method add the following
$this->createTable('{{%post_translation}}', [
'post_id' => Schema::TYPE_INTEGER . ' NOT NULL',
'language' => Schema::TYPE_STRING . '(16) NOT NULL',
'title' => Schema::TYPE_STRING . ' NOT NULL',
'body' => Schema::TYPE_TEXT . ' NOT NULL',
]);
$this->addPrimaryKey('', '{{%post_translation}}', ['post_id', 'language']);Configure model as follows
…Model PostTranslation can be generated using Gii.
To set translations to the entity
…To get translations from the entity
…To check translations in the entity
$post = Post::findOne(1);
// checking for default application language translation
$result = $post->hasTranslation();
// checking for German translation
$result = $post->hasTranslation('de-DE');
// checking for Russian translation
$result = $post->hasTranslation('ru-RU');Example of controller actions
…Example of view form
field($model->translate($language), "[$language]title")->textInput();
echo $form->field($model->translate($language), "[$language]body")->textarea();
}
//...
ActiveForm::end();Example of model attribute labels
…Support this project and others by creocoder via gratipay.
No open issues yet, or sync has not completed.