コード例 #1
0
 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);
 }
コード例 #2
0
 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;
 }
コード例 #3
0
<?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();