<?php


class MissingTranslationEventHandler
{
    /**
     * @param CMissingTranslationEvent $event
     * @return void
     */
    public function missingTranslation($event)
    {

        $model = SourceMessage::model()->find(
            'category = :category and message COLLATE utf8_bin like :message COLLATE utf8_bin',  //case sensitive like
            array(
                ':category' => $event->category,
                ':message' => $event->message,
            ));


        if ($model === null) {
            $model = new SourceMessage();
            $model->category = $event->category;
            $model->message = $event->message;
            $model->save();
// migration from old message source

//        /**
//         * @var CPhpMessageSource $oldOne
//         */
//        $oldOne = Yii::app()->oldOne;
//        foreach (Yii::app()->params['languages'] as $lang) {
//            $tr = new Message();
//            $tr->id = $model->id;
//            $tr->language = $lang;
//            $tr->translation = $oldOne->translate($event->category, $event->message, $lang);
//            if ($tr->translation != $event->message)
//                $tr->save();
//        }
        }

    }
}