コード例 #1
0
ファイル: Language.php プロジェクト: ivphpan/iris
 public static function t($category, $t, $resetCategory = false)
 {
     if (empty($t)) {
         return 'Empty text';
     }
     if (empty(self::$t[$category]) || $resetCategory) {
         $categoryList = self::find()->where(['lang' => \Yii::$app->language])->all();
         self::$t[$category] = [];
         foreach ($categoryList as $categoryItem) {
             self::$t[$categoryItem->category][$categoryItem->alias] = $categoryItem->t;
         }
         $resetCategory = false;
     }
     $t = trim($t);
     $alias = md5(gzcompress($t));
     if (!empty(self::$t[$category][$alias])) {
         return self::$t[$category][$alias];
     }
     $model = new Language();
     $model->id = $model->nextId;
     $model->lang = Lang::getLang()->code;
     $model->alias = $alias;
     $model->category = $category;
     $model->t = $t;
     $model->create();
     return self::t($category, $t, true);
 }