Example #1
0
 /**
  * Adds a language JS locale file
  *
  * @param string $lang the ISO language code
  * @param string $prefix the language locale file name prefix
  * @param string $dir the language file directory relative to source path
  * @param bool $min whether to auto use minified version
  *
  * @return AssetBundle instance
  */
 public function addLanguage($lang = '', $prefix = '', $dir = null, $min = false)
 {
     if (empty($lang) || substr($lang, 0, 2) == 'en') {
         return $this;
     }
     $ext = $min ? YII_DEBUG ? ".min.js" : ".js" : ".js";
     $file = "{$prefix}{$lang}{$ext}";
     if ($dir === null) {
         $dir = 'js';
     } elseif ($dir === "/") {
         $dir = '';
     }
     $path = $this->sourcePath . '/' . $dir;
     if (!Config::fileExists("{$path}/{$file}")) {
         $lang = Config::getLang($lang);
         $file = "{$prefix}{$lang}{$ext}";
     }
     if (Config::fileExists("{$path}/{$file}")) {
         $this->js[] = empty($dir) ? $file : "{$dir}/{$file}";
     }
     return $this;
 }
Example #2
0
 private function initSiteConfig()
 {
     // lang
     $langs = Config::getLang();
     $currentLang = isset($langs[0]) ? $langs : $this->lang;
     $langGet = Util\Converter::string('lang');
     if (isset($langGet)) {
         $currentLang = $langGet;
     } else {
         if (isset($_COOKIE['lang'])) {
             $currentLang = $_COOKIE['lang'];
         }
     }
     $validLang = false;
     if (isset($langs[$currentLang])) {
         $validLang = true;
     }
     if (!$validLang) {
         $currentLang = $this->lang;
     }
     $this->lang = $currentLang;
     if (!isset($_COOKIE['lang']) || $_COOKIE['lang'] != $this->lang) {
         // 7 days
         $expire = time() + 60 * 60 * 24 * 7;
         setcookie('lang', $this->lang, $expire, '/', Util\Nav::removePort($this->siteUrl));
     }
     setlocale(LC_ALL, $langs[$this->lang]);
     // site
     $this->site = \Rebond\Core\Site\Data::loadById(1);
     $this->env = $this->site->getEnvironment();
     $this->skin = $this->site->getSkin();
     if ($this->env == Config::ENV_PROD) {
         $this->setLogLevel(Config::ENV_PROD);
     }
     $this->timezone = $this->site->getTimezone();
     date_default_timezone_set($this->timezone);
 }