コード例 #1
0
 public static function handleMissingTranslation(MissingTranslationEvent $event)
 {
     $fallbackTranslation = SourceMessage::getMessageTranslation($event->category, $event->message, Yii::$app->params['fallbackLanguage']);
     if (isset($fallbackLanguage) && !empty($fallbackLanguage->translation)) {
         return $event->translatedMessage = $fallbackLanguage->translation;
     }
     $mainLanguageTranslation = SourceMessage::getMessageTranslation($event->category, $event->message, Yii::$app->params['appMainLanguage']);
     if (isset($mainLanguageTranslation) && !empty($mainLanguageTranslation->translation)) {
         return $event->translatedMessage = $mainLanguageTranslation->translation;
     }
 }
コード例 #2
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 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;
 }
コード例 #3
0
 public function actionSaveTranslation($id)
 {
     $sourceMessage = SourceMessage::findOne($id);
     if (!isset($sourceMessage)) {
         throw new HttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     $translations = $sourceMessage->initializeTranslations();
     if (SourceMessage::loadMultiple($translations, Yii::$app->getRequest()->post()) && SourceMessage::validateMultiple($translations)) {
         $sourceMessage->saveTranslations($translations);
         Yii::$app->session->setFlash('success', Yii::t('app', 'Translations saved successfully'));
     } else {
         Yii::$app->session->setFlash('error', Yii::t('app', 'Error saving translation'));
     }
     return $this->redirect(['translate-frontend']);
 }
コード例 #4
0
ファイル: SiteController.php プロジェクト: HeavyDots/heavyCMS
 public function actionSaveTranslation($id)
 {
     if (Yii::$app->request->isAjax) {
         try {
             $sourceMessage = SourceMessage::findOne($id);
             $translations = $sourceMessage->initializeTranslations();
             if (SourceMessage::loadMultiple($translations, Yii::$app->getRequest()->post()) && SourceMessage::validateMultiple($translations)) {
                 $sourceMessage->saveTranslations($translations);
                 $message = Yii::t('app', 'Saved');
             }
         } catch (Exception $e) {
             $message = Yii::t('app', 'Error');
         }
         return $message;
     }
 }
コード例 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSourceMessage()
 {
     return $this->hasOne(\backend\models\SourceMessage::className(), ['id' => 'id']);
 }
コード例 #6
0
<?php

/* TODO: Make Save Buttons AJAX */
use yii\helpers\Html;
use yii\grid\GridView;
use yii\grid\ActionColumn;
use dmstr\widgets\Alert;
use backend\models\SourceMessage;
$this->title = Yii::t('app', 'Translate UI');
$this->params['breadcrumbs'][] = $this->title;
?>

<?php 
echo Alert::widget();
?>

<?php 
echo GridView::widget(['dataProvider' => $sourceMessageProvider, 'filterModel' => $sourceMessageSearch, 'id' => 'translate-frontend-grid', 'tableOptions' => ['class' => 'table table-striped table-bordered box box-primary'], 'columns' => [['attribute' => 'message', 'format' => 'raw', 'contentOptions' => ['class' => 'source-message']], ['label' => Yii::t('app', 'Message Translations'), 'format' => 'raw', 'headerOptions' => ['width' => '600'], 'value' => function ($model, $key, $index, $column) {
    return $this->render('_message-tabs', ['model' => $model, 'key' => $key, 'index' => $index, 'column' => $column]);
}], ['attribute' => 'category', 'contentOptions' => ['class' => 'text-center'], 'filter' => Html::activeDropDownList($sourceMessageSearch, 'category', SourceMessage::getAllCategoriesAsArray(), ['class' => 'form-control', 'prompt' => Yii::t('app', 'All')])], ['class' => ActionColumn::className(), 'template' => '{save}', 'buttons' => ['save' => function ($url, $sourceMessageSearch, $key) {
    return Html::a('<i class="glyphicon glyphicon-floppy-disk"></i> ' . Yii::t('app', 'Save'), '#', ['class' => 'btn btn-success btn-translation-save', 'title' => Yii::t('app', 'Save')]);
}]]]]);
// Create submit button
コード例 #7
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\grid\ActionColumn;
use dmstr\widgets\Alert;
use backend\models\SourceMessage;
$this->title = Yii::t('app', 'Translate UI');
$this->params['breadcrumbs'][] = $this->title;
?>

<?php 
echo Alert::widget();
?>

<?php 
echo GridView::widget(['dataProvider' => $sourceMessageProvider, 'filterModel' => $sourceMessageSearch, 'id' => 'translate-frontend-grid', 'tableOptions' => ['class' => 'table table-striped table-bordered box box-primary'], 'columns' => [['attribute' => 'category', 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['width' => '100'], 'filter' => Html::activeDropDownList($sourceMessageSearch, 'category', SourceMessage::getAllCategoriesAsArray(), ['class' => 'form-control', 'prompt' => Yii::t('app', 'All')])], ['attribute' => 'message', 'format' => 'raw', 'contentOptions' => ['class' => 'source-message'], 'headerOptions' => ['width' => '150']], ['label' => Yii::t('app', 'Message Translations'), 'format' => 'raw', 'headerOptions' => ['width' => '600'], 'value' => function ($model, $key, $index, $column) {
    return $this->render('_message-tabs', ['model' => $model, 'key' => $key, 'index' => $index, 'column' => $column]);
}]]]);