public function actionIndexWithDescriptions()
 {
     if (isset($_POST['Room'])) {
         $roomsInput = $_POST['Room'];
         foreach ($roomsInput as $item) {
             $sourceMessage = \common\models\SourceMessage::findOne(['message' => $item['description']]);
             // If null, I need to create source message
             if ($sourceMessage == null) {
                 $sourceMessage = new \common\models\SourceMessage();
             }
             $sourceMessage->category = 'app';
             $sourceMessage->message = $item['description']['en'];
             $sourceMessage->save();
             $otherLanguages = ['zh-cn'];
             foreach ($otherLanguages as $otherLang) {
                 $message = \common\models\Message::findOne(['id' => $sourceMessage->id, 'language' => $otherLang]);
                 if ($message == null) {
                     $message = new \common\models\Message();
                 }
                 $message->id = $sourceMessage->id;
                 $message->language = $otherLang;
                 $message->translation = $item['description'][$otherLang];
                 $message->save();
             }
             // Room to update
             $roomToUpdate = \frontend\models\BaseRoom::findOne($item['id']);
             $roomToUpdate->description = $item['description']['en'];
             $roomToUpdate->save();
         }
     }
     $rooms = BaseRoom::find()->all();
     return $this->render('indexWithDescriptions', ['rooms' => $rooms]);
 }
 /**
  * Insert missing translation to php file
  * @param $event MissingTranslationEvent
  */
 public function insertMissingTranslation($event)
 {
     Yii::$app->cache->flush();
     /* find source */
     $source = SourceMessage::find()->where('`category`=:category AND BINARY `message`=:message')->params([':category' => $event->category, ':message' => $event->message])->one();
     /* create source message if no exist */
     if (!$source) {
         $source = new SourceMessage();
         $source->category = $event->category;
         $source->message = $event->message;
         $source->save();
     }
     //file_put_contents('d:\log1.txt', $event->message);
     /* add translate message */
     Yii::$app->db->createCommand()->insert($this->messageTable, ['id' => $source->id, 'language' => $event->language, 'translation' => $event->message])->execute();
     //file_put_contents('D:\log.txt', 'mission');
 }
Exemple #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SourceMessage::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }
 /**
  * Finds SourceMessage model by quering or creating new one
  * @param  string $field       Name of the owner's field that's linked
  * @param  bool   $onlyMessage Whether to return model instance or string
  * @param  bool   $translation Whether to return translated message. Be sure
  *                             that $language param is set and it differs
  *                             from $defaultLanguage
  * @return mixed               \common\models\SourceMessage or string
  *                             depending on the $onlyMessage param
  */
 public function findSourceMessage($field, $onlyMessage = true, $translation = true)
 {
     if (!empty($this->_messages[$field])) {
         $model = $this->_messages[$field];
         return $onlyMessage ? $model->message : $model;
     }
     $owner = $this->owner;
     $model = null;
     if (!empty($owner->{$field})) {
         $model = SourceMessage::findOne($owner->{$field});
     }
     if ($model === null) {
         $model = new SourceMessage(['category' => $owner::tableName(), 'message' => null]);
     }
     $this->_messages[$field] = $model;
     $language = $this->language;
     $defaultLanguage = $this->defaultLanguage;
     // Get translated model if $model->language is set
     if (!empty($language && $language !== $defaultLanguage) && $translation) {
         return $model->getTranslation($language, $onlyMessage);
     }
     return $onlyMessage === true ? $model->message : $model;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SourceMessage::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'message', $this->message]);
     //$query->andFilterWhere([
     //    'DATE(FROM_UNIXTIME(`created_at`))' => $this->created_at,
     //]);
     return $dataProvider;
 }
Exemple #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getId0()
 {
     return $this->hasOne(SourceMessage::className(), ['id' => 'id']);
 }
 /**
  * get category list
  * @return array
  */
 public static function getCategoryList()
 {
     $items = SourceMessage::find()->select(['category'])->distinct()->all();
     return ArrayHelper::map($items, 'category', 'category');
 }
Exemple #8
0
$this->params['breadcrumbs'][] = $this->title;
//$this->registerJs('$(document).on("pjax:send", function(){ $("#loading").modal("show");});$(document).on("pjax:complete", function(){ $("#loading").modal("hide");})');
$this->registerJs('$(document).on("pjax:send", function(){ $(".grid-view-overlay").removeClass("hidden");});$(document).on("pjax:complete", function(){ $(".grid-view-overlay").addClass("hidden");})');
//$js=file_get_contents(__DIR__.'/index.min.js');
//$this->registerJs($js);
$css = file_get_contents(__DIR__ . '/index.css');
$this->registerCss($css);
?>
<div class="i18n-message-index">
    <div class="box box-primary">
        <div class="box-body">
            <?php 
Pjax::begin(['id' => 'message-translation-wrap']);
?>
    <?php 
echo GridView::widget(['id' => 'i18n-message-grid', 'options' => ['class' => 'grid-view table-responsive'], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'language', 'value' => 'language', 'filter' => Message::getLocaleList([Yii::$app->sourceLanguage])], ['attribute' => 'category', 'value' => 'source.category', 'filter' => SourceMessage::getCategoryList()], ['attribute' => 'message', 'value' => 'source.message'], ['attribute' => 'translation', 'format' => 'raw', 'value' => function ($model) {
    return \modernkernel\jeditable\Editable::widget(['content' => strip_tags($model->translation), 'saveUrl' => Yii::$app->urlManager->createUrl(['/i18n/save-translation']), 'options' => ['id' => 'message_' . $model->id . '_' . $model->language, 'class' => 'jeditable-text'], 'clientOptions' => ['tooltip' => Yii::t('app', 'Click to edit'), 'indicator' => Yii::t('app', 'Saving...'), 'width' => '93%']]);
}], ['attribute' => 'is_translated', 'value' => function ($model) {
    return Core::getYesNoText($model->is_translated);
}, 'filter' => Core::getYesNoOption()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}']]]);
?>
            <?php 
Pjax::end();
?>
            <div>
                <?php 
echo \yii\helpers\Html::beginForm(Yii::$app->urlManager->createUrl(['/i18n/add']), 'post', ['class' => 'form-inline']);
?>
                    <div class="form-group">
                        <label for="language"><?php 
echo Yii::t('app', 'Language');
Exemple #9
0
 /**
  * Finds the SourceMessage model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SourceMessage the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SourceMessage::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #10
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['title', 'content', 'url_alias'], 'required'], [['content', 'metadescription', 'metakeywords', 'metatitle', 'title'], 'string'], [['created_at', 'updated_at'], 'integer'], [['url_alias'], 'string', 'max' => 255], [['content_id'], 'exist', 'skipOnError' => true, 'targetClass' => SourceMessage::className(), 'targetAttribute' => ['content_id' => 'id']], [['meta_description_id'], 'exist', 'skipOnError' => true, 'targetClass' => SourceMessage::className(), 'targetAttribute' => ['meta_description_id' => 'id']], [['meta_keywords_id'], 'exist', 'skipOnError' => true, 'targetClass' => SourceMessage::className(), 'targetAttribute' => ['meta_keywords_id' => 'id']], [['meta_title_id'], 'exist', 'skipOnError' => true, 'targetClass' => SourceMessage::className(), 'targetAttribute' => ['meta_title_id' => 'id']], [['title_id'], 'exist', 'skipOnError' => true, 'targetClass' => SourceMessage::className(), 'targetAttribute' => ['title_id' => 'id']]];
 }