예제 #1
0
파일: LangRequest.php 프로젝트: apurey/cmf
 /**
  * @return bool|string
  */
 protected function resolveRequestUri()
 {
     $pattern = [];
     $resolveRequestUri = parent::resolveRequestUri();
     if (Yii::$app->getUrlManager()->enablePrettyUrl === true) {
         $pattern[] = '/' . preg_replace('/\\//', '\\/', Yii::$app->getUrlManager()->suffix) . '/';
     }
     if (Yii::$app->getUrlManager()->showScriptName === true) {
         $pattern[] = '/' . preg_replace('/\\//', '\\/', $this->getScriptUrl()) . '/';
     }
     $requestUri = preg_replace($pattern, '', $resolveRequestUri);
     list($language, ) = explode('/', trim($requestUri, '/'));
     if (Language::isLanguage($language)) {
         Language::setCurrent($language);
     } else {
         Language::setCurrent($this->getPreferredLanguage(ArrayHelper::getColumn(Language::listing(), 'iso')));
     }
     return $resolveRequestUri;
 }
예제 #2
0
 public static function handleMissingTranslation(MissingTranslationEvent $event)
 {
     $i18nSource = I18nSource::findOne(['category' => $event->category, 'message' => $event->message]);
     if ($i18nSource === null) {
         $i18nSource = new I18nSource();
         $i18nSource->category = $event->category;
         $i18nSource->message = $event->message;
         $i18nSource->save();
     }
     foreach (Language::listing() as $language) {
         $i18nMessage = I18nMessage::findOne(['id' => $i18nSource->id, 'language' => $language['iso']]);
         if ($i18nMessage === null) {
             $i18nMessage = new I18nMessage();
             $i18nMessage->id = $i18nSource->id;
             $i18nMessage->language = $language['iso'];
             $i18nMessage->translation = $event->message;
             $i18nMessage->save();
         }
     }
 }
예제 #3
0
 /**
  * Displays a single I18nSource model.
  * @param string $id
  * @return mixed
  */
 public function actionView($id)
 {
     return $this->render('view', ['model' => $this->findModel($id), 'language' => ArrayHelper::map(Language::listing(), 'iso', 'title')]);
 }
예제 #4
0
 public function init()
 {
     $this->languages = Language::listing();
 }