All Projects → yiimaker → yii2-translatable

yiimaker / yii2-translatable

Licence: BSD-3-Clause license
Translatable behavior aggregates logic of linking translations to the primary model

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-translatable

yii2-behaviors
Collection of useful behaviors for Yii Framework 2.0
Stars: ✭ 25 (+66.67%)
Mutual labels:  yii2, yii2-behaviors, yii2-extension
yii2-linkable-behavior
Yii2 behavior to help creating urls easier
Stars: ✭ 12 (-20%)
Mutual labels:  yii2, yii2-behaviors, yii2-extension
content
Content management system for Yii2
Stars: ✭ 54 (+260%)
Mutual labels:  yii2, yii2-extension
Yii2 Comments
Comments module for Yii2
Stars: ✭ 155 (+933.33%)
Mutual labels:  yii2, yii2-extension
install
basic script for project installation
Stars: ✭ 17 (+13.33%)
Mutual labels:  yii2, yii2-extension
Yii2 Rbac
RBAC Manager for Yii 2
Stars: ✭ 128 (+753.33%)
Mutual labels:  yii2, yii2-extension
Yii2 Wx
这可能是yii2中最好用的微信SDK🔥🔥🔥
Stars: ✭ 148 (+886.67%)
Mutual labels:  yii2, yii2-extension
Balance
Balance accounting (bookkeeping) system based on debit and credit principle
Stars: ✭ 162 (+980%)
Mutual labels:  yii2, yii2-extension
Yii2 Phone Input
Yii2 International telephone numbers
Stars: ✭ 114 (+660%)
Mutual labels:  yii2, yii2-extension
Ar Softdelete
Soft delete behavior for ActiveRecord
Stars: ✭ 188 (+1153.33%)
Mutual labels:  yii2, yii2-extension
Yii2 Enhanced Gii
Enhanced Yii2 Gii (generator) that generates related Models & CRUD
Stars: ✭ 183 (+1120%)
Mutual labels:  yii2, yii2-extension
Yii2 Translate Manager
Translation Manager
Stars: ✭ 221 (+1373.33%)
Mutual labels:  yii2, yii2-extension
Yii2fullcalendar
JQuery Fullcalendar Yii2 Extension
Stars: ✭ 120 (+700%)
Mutual labels:  yii2, yii2-extension
Yii2 Cart
Yii2 shopping cart
Stars: ✭ 118 (+686.67%)
Mutual labels:  yii2, yii2-extension
Yii2 Assets Auto Compress
Automatic compilation of js + css + html
Stars: ✭ 147 (+880%)
Mutual labels:  yii2, yii2-extension
File Storage
File storage abstraction for Yii2
Stars: ✭ 116 (+673.33%)
Mutual labels:  yii2, yii2-extension
Yii2 Workflow
A simple workflow engine for Yii2
Stars: ✭ 157 (+946.67%)
Mutual labels:  yii2, yii2-extension
yii2-lets-talk
With this extension you can open chat with someone in popular messengers using the link on your website.
Stars: ✭ 15 (+0%)
Mutual labels:  yii2, yii2-extension
Admin
Admin pack (actions, widgets, etc) for Yii2
Stars: ✭ 100 (+566.67%)
Mutual labels:  yii2, yii2-extension
Ar Position
ActiveRecord behavior, which provides ability for custom records order setup
Stars: ✭ 107 (+613.33%)
Mutual labels:  yii2, yii2-extension

Stand With Ukraine

Translatable behavior

Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version StandWithUkraine

Translatable behavior aggregates logic of linking translations to the primary model.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require yiimaker/yii2-translatable

or add

"yiimaker/yii2-translatable": "~1.0"

to the require section of your composer.json.

Usage

  1. Add behavior to the your primary model
public function behaviors()
{
    return [
        // ...
        'translatable' => [
            'class' => TranslatableBehavior::className(),
            // 'translationRelationName' => 'translations',
            // 'translationLanguageAttrName' => 'language',
            // 'attributeNamePattern' => '%name% [%language%]',
            'translationAttributeList' => [
                'title',
                'description',
            ],
        ],
    ];
}
  1. And use getTranslation() or translateTo() methods
// product is an active record model with translatable behavior
$product = new Product();

// sets translation for default application language
$product->title = 'PhpStrom 2018.1';
$product->description = 'Лицензия PhpStrom IDE версия 2018.1';

// gets translation for English language
$translation = $product->getTranslation('en');
$translation->title = 'PhpStrom 2018.1';
$translation->description = 'License of the PhpStrom IDE version 2018.1';

// sets description for French language
$product->translateTo('fr')->description = 'La licence de PhpStorm IDE la version 2018.1';

$product->insert();

translateTo() it's just an alias for getTranslation() method.

After saving the model you can fetch this model from the database and translatable behavior will fetch all translations automatically.

$product = Product::find()
    ->where(['id' => 1])
    ->with('translations')
    ->one()
;

// gets translation for English language
$product->translateTo('en')->description; // License of the PhpStrom IDE version 2018.1
// gets translation for French language
$product->translateTo('fr')->description; // La licence de PhpStorm IDE la version 2018.1

// check whether Ukrainian translation not exists
if (!$product->hasTranslation('uk')) {
    $product->translateTo('uk')->description = 'Ліцензія PhpStrom IDE версія 2018.1';
}

// update Enlish translation
$product->translateTo('en')->title = 'PhpStorm IDE';

$product->update();

Tests

You can run tests with composer command

$ composer test

or using following command

$ codecept build && codecept run

Contributing

For information about contributing please read CONTRIBUTING.md.

Sponsoring

Buy Me A Coffee

License

License

This project is released under the terms of the BSD-3-Clause license.

Copyright (c) 2017-2022, Yii Maker

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].