Пример #1
0
 public function frontendPrePageResolve($context)
 {
     if (!self::$resolved) {
         // get languages from configuration
         if (self::$languages = Symphony::Configuration()->get('languages', 'multilingual')) {
             self::$languages = explode(',', str_replace(' ', '', self::$languages));
             // detect language from path
             if (preg_match('/^\\/([a-z]{2})\\//', $context['page'], $match)) {
                 // set language from path
                 self::$language = $match[1];
             } else {
                 // detect language from browser
                 self::$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
             }
             // check if language is supported
             if (!in_array(self::$language, self::$languages)) {
                 // set to default otherwise
                 self::$language = self::$languages[0];
             }
             // redirect root page
             if (!$context['page']) {
                 header('Location: ' . URL . '/' . self::$language . '/');
                 exit;
             }
         }
         self::$resolved = true;
     }
 }
Пример #2
0
 public function frontendPrePageResolve($context)
 {
     if (!self::$resolved) {
         // get languages from configuration
         if (self::$languages = Symphony::Configuration()->get('languages', 'multilingual')) {
             self::$languages = explode(',', str_replace(' ', '', self::$languages));
             // detect language from path
             if (preg_match('/^\\/([a-z]{2})\\//', $context['page'], $match)) {
                 // set language from path
                 self::$language = $match[1];
             } else {
                 if (isset($_SESSION['language'])) {
                     // detect if session has language set
                     self::$language = substr($_SESSION['language'], 0, 2);
                 } else {
                     // detect language from browser
                     $browserLang = preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\\s*(;\\s*q\\s*=\\s*(1|0\\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
                     $browserLang = reset($lang_parse[0]);
                     if (in_array("pt-br", reset($lang_parse))) {
                         $browserLang = "pb";
                     }
                     if (in_array("es-mx", reset($lang_parse))) {
                         $browserLang = "mx";
                     }
                     self::$language = substr($browserLang, 0, 2);
                 }
             }
             // check if language is supported
             if (!in_array(self::$language, self::$languages)) {
                 // set to default otherwise
                 self::$language = self::$languages[0];
             }
             // redirect root page
             if (!$context['page']) {
                 // header('Location: ' . URL . '/' . self::$language . '/'); exit;
             }
         }
         self::$resolved = true;
     }
 }