public static function getStatus($id = null) { $statuses = [self::STATUS_TRANSLATED => Module::t('Translated'), self::STATUS_NOT_TRANSLATED => Module::t('Not translated')]; if ($id !== null) { return ArrayHelper::getValue($statuses, $id, null); } return $statuses; }
/** * * @param array|integer $id * @return SourceMessage|SourceMessage[] * @throws NotFoundHttpException */ protected function findModel($id) { $query = SourceMessage::find()->where('id = :id', [':id' => $id]); $models = is_array($id) ? $query->all() : $query->one(); if (!empty($models)) { return $models; } else { throw new NotFoundHttpException(Module::t('The requested page does not exist')); } }
public function initMessages() { $messages = []; foreach (Module::getInstallLanguages() as $language) { if (!isset($this->messages[$language])) { $message = new Message(); $message->language = $language; $messages[$language] = $message; } else { $messages[$language] = $this->messages[$language]; } } $this->populateRelation('messages', $messages); }
public function translated() { $messageTableName = Message::tableName(); $query = Message::find()->select($messageTableName . '.id'); $i = 0; foreach (Module::getInstallLanguages() as $language) { if ($i === 0) { $query->andWhere($messageTableName . '.language = :language and ' . $messageTableName . '.translation is not null', [':language' => $language]); } else { $query->innerJoin($messageTableName . ' t' . $i, 't' . $i . '.id = ' . $messageTableName . '.id and t' . $i . '.language = :language and t' . $i . '.translation is not null', [':language' => $language]); } $i++; } $ids = $query->indexBy('id')->all(); $this->andWhere(['in', 'id', array_keys($ids)]); return $this; }
I18nAsset::register($this); $this->title = Module::t('Translations'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="box box-solid"> <div class="box-body no-padding"> <?php echo GridView::widget(['layout' => "{items}", 'filterModel' => $searchModel, 'dataProvider' => $dataProvider, "tableOptions" => ['class' => 'table table-hover table-striped no-margin'], 'columns' => [['attribute' => 'message', 'format' => 'raw', 'contentOptions' => ['class' => 'source-message'], 'value' => function ($model, $index, $widget) { return Html::a($model->message, ['update', 'id' => $model->id], ["class" => "source-message-content"]); }], ['class' => ActionColumn::className(), 'header' => '<i class="fa fa-copy"></i>', 'template' => '{copy}', 'headerOptions' => ['width' => '30'], 'buttons' => ['copy' => function ($url, $model, $key) { return Html::a('<i class="fa fa-arrow-right "></i>', 'javascript:void(0);', ['class' => 'btn btn-xs btn-default btn-translation-copy-from-source', 'title' => Module::t('Copy from source message')]); }]], ['attribute' => 'messages', 'headerOptions' => ['width' => '400'], 'contentOptions' => ['class' => 'tabs-mini'], 'value' => function ($model, $key, $index, $column) { return $this->render('_message-tabs', ['model' => $model, 'key' => $key, 'index' => $index, 'column' => $column]); }, 'format' => 'raw'], ['attribute' => 'category', 'headerOptions' => ['width' => '150'], 'contentOptions' => ['class' => 'text-align-center'], 'value' => function ($model, $key, $index, $dataColumn) { return $model->category; }, 'filter' => ArrayHelper::map($searchModel::getCategories(), 'category', 'category')], ['attribute' => 'status', 'headerOptions' => ['width' => '150'], 'contentOptions' => ['class' => 'text-align-center'], 'value' => function ($model, $index, $widget) { /** @var SourceMessage $model */ return $model->isTranslated() ? 'Translated' : 'Not translated'; }, 'filter' => $searchModel->getStatus()], ['class' => ActionColumn::className(), 'template' => '{save} ', 'buttons' => ['save' => function ($url, $model, $key) { return Html::a('<i class="glyphicon glyphicon-download"></i> ' . Module::t('Save'), 'javascript:void(0);', ['class' => 'btn btn-xs btn-success btn-translation-save', "data-url" => Url::to(["update", "id" => $model->primaryKey])]); }]]]]); ?> </div> <div class="box-footer"> <div class="box-tools pull-right"> <?php echo yii\widgets\LinkPager::widget(['pagination' => $dataProvider->pagination, 'options' => ['class' => 'pagination pagination-sm inline']]); ?> </div> </div> </div>
$this->title = Module::t('Update') . ': ' . $model->message; ?> <div class="message-update"> <div class="message-form"> <?php $form = ActiveForm::begin(); ?> <div class="field"> <div class="ui grid"> <?php foreach ($model->messages as $language => $message) { ?> <div class="four wide column"> <?php echo $form->field($model->messages[$language], '[' . $language . ']translation')->label($language); ?> </div> <?php } ?> </div> </div> <?php echo Html::submitButton(Module::t('Update'), ['class' => 'ui primary button']); ?> <?php $form::end(); ?> </div> </div>
<?php use yii\helpers\Html; use yii\bootstrap\Tabs; use hass\i18n\Module; $items = []; foreach (Module::getInstallLanguages() as $lang) { $message = Yii::t($model->category, $model->message, [], $lang); $message = $model->message == $message && $lang != Module::getInstallLanguages()[0] ? '' : $message; $items[] = ['label' => '<b>' . strtoupper($lang) . '</b>', 'content' => Html::textInput('Message[' . $lang . '][translation]', $message, ['id' => 'message-' . $lang . '-translation', 'class' => 'form-control', 'rel' => $lang, 'dir' => in_array($lang, ['ar', 'fa']) ? 'rtl' : 'ltr', 'rows' => 3]) . Html::hiddenInput('categories[' . $lang . ']', $model->category), 'active' => $lang == Yii::$app->language ? true : false]; } echo Html::beginForm("", "post", ["class" => "translation-save-form"]); echo Tabs::widget(['encodeLabels' => false, 'items' => $items]); echo Html::endForm();
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('ID'), 'language' => Module::t('Language'), 'translation' => Module::t('Translation')]; }