public function actionClearCache()
 {
     // ---------------------- CHECK IS AJAX REQUEST ------------------------
     if (!Yii::$app->getRequest()->isAjax) {
         return $this->redirect(['/translations']);
     }
     // ------------------ SET JSON FORMAT FOR RESPONSE ---------------------
     // @see https://github.com/samdark/yii2-cookbook/blob/master/book/response-formats.md
     Yii::$app->getResponse()->format = \yii\web\Response::FORMAT_JSON;
     // ---------------------- SET DEFAULT RESPONSE -------------------------
     $response = array('status' => 'error', 'message' => Module::t('An unexpected error occured!'));
     // -------------------------- CLEAR CACHE ------------------------------
     if (SourceMessageSearch::cacheFlush()) {
         $response['status'] = 'success';
         $response['message'] = Module::t('Translations cache successfully cleared.');
     }
     return $response;
 }
Example #2
0
$this->title = Module::t('Translations');
$this->params['breadcrumbs'][] = $this->title;
AppTranslateAsset::register($this);
?>

<div class="translations-index">
    <div class="row">
        <div class="col-lg-12">
            <span class="pull-left btn-group">
            <?php 
foreach ([SourceMessageSearch::STATUS_ALL => Module::t('All'), SourceMessageSearch::STATUS_TRANSLATED => Module::t('Translated'), SourceMessageSearch::STATUS_NOT_TRANSLATED => Module::t('Not Translated'), SourceMessageSearch::STATUS_DELETED => Module::t('Deleted')] as $status => $name) {
    ?>
                <a class="btn btn-default <?php 
    $params = ArrayHelper::merge(Yii::$app->request->getQueryParams(), [$searchModel->formName() => ['status' => $status]]);
    $route = ArrayHelper::merge(['/translations'], $params);
    echo SourceMessageSearch::isActiveTranslation(['url' => $route, 'current' => $status]);
    ?>
" href="<?php 
    echo Url::to($route);
    ?>
"><?php 
    echo $name;
    ?>
</a>
            <?php 
}
?>
            </span>
        </div>
    </div>
    <h2>
Example #3
0
 /**
  * Extracts messages to be translated from source code.
  *
  * Example from yii console:
  * ```
  * php yii message/extract @common/config/messages.php
  * ```
  *
  * This command will search through source code files and extract
  * messages that need to be translated in different languages.
  *
  * @param string $configFile the path or alias of the configuration file.
  * You may use the "yii message/config" command to generate
  * this file and then customize it for your needs.
  * @throws Exception on failure.
  */
 public function actionExtract($configFile)
 {
     SourceMessageSearch::getInstance()->extract();
 }