lajax / yii2-translate-manager

Translation Manager
MIT License
227 stars 90 forks source link

Loosing DB data #26

Closed xenolOnline closed 9 years ago

xenolOnline commented 9 years ago

Hello, I use your awesome extension. I translate db message like this:

public $name_t;
public function afterFind() {
    $this->name_t = Language::d($this->name);
    $this->description_t = Language::d($this->descrioption);
    parent::afterFind();
}

public function beforeSave($insert) {
    if (parent::beforeSave($insert)) {
        Language::saveMessage($this->name);
        Language::saveMessage($this->description);

        return true;
    }

    return false;
}

But when I click on Scan link all database records will be found, and if I click on Optimize link (accidentally) script will remove my translations. But these mesages are still in use

moltam commented 9 years ago

Hey! You should add the table to the extension configuration as seen in this example in the readme file:

'tables' => [                   // Properties of individual tables
    [
        'connection' => 'db',   // connection identifier
        'table' => '{{%language}}',  // table name
        'columns' => ['name', 'name_ascii']  //names of multilingual fields
    ],
]

This way the extension will scan your columns for language elements, and it won't delete them (because the extension will find the original data in your table, and it knows that you still use them). The scanner will find new elements as well, so you can remove the manual message save in the beforeInsert() method (but you need to manually run the scan to find new elements if you do this).

xenolOnline commented 9 years ago

Yes, You are right, Sorry for my inattention

lajax commented 9 years ago

Thanks for the quick reply!