Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
Y

yii2-translateable

> 编程语言
Open source

The translateable behavior for the Yii framework.

99 stars0 likes1 views
WebsiteGitHub

About

The translateable behavior for the Yii framework.

Translateable Behavior for Yii 2

A modern translateable behavior for the Yii framework.

Installation

The preferred way to install this extension is through composer.

Either run

bash
$ composer require creocoder/yii2-translateable

or add

"creocoder/yii2-translateable": "~1.0"

to the require section of your composer.json file.

Migrations

Run the following command

bash
$ yii migrate/create create_post_table

Open the /path/to/migrations/m_xxxxxx_xxxxxx_create_post_table.php file, inside the up() method add the following

php
$this->createTable('{{%post}}', [
    'id' => Schema::TYPE_PK,
]);

Run the following command

bash
$ yii migrate/create create_post_translation_table

Open the /path/to/migrations/m_xxxxxx_xxxxxx_create_post_translation_table.php file, inside the up() method add the following

php
$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']);

Configuring

Configure model as follows

…

Model PostTranslation can be generated using Gii.

Usage

Setting translations to the entity

To set translations to the entity

…

Getting translations from the entity

To get translations from the entity

…

Checking for translations in the entity

To check translations in the entity

php
$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');

Advanced usage

Collecting tabular input

Example of controller actions

…

Example of view form

php
field($model->translate($language), "[$language]title")->textInput();
    echo $form->field($model->translate($language), "[$language]body")->textarea();
}

//...

ActiveForm::end();

Language specific translation attribute labels

Example of model attribute labels

…

Donating

Support this project and others by creocoder via gratipay.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言