Ejemplo n.º 1
0
 /**
  * Change language in cookie while clicking on a flag
  *
  * @param null $cookie
  * @return string iso code
  */
 public static function setCookieLanguage($cookie = null)
 {
     if (!$cookie) {
         $cookie = JeproshopContext::getContext()->cookie;
     }
     /* If language does not exist or is disabled, erase it */
     if ($cookie->lang_id) {
         $lang = new JeproshopLanguageModelLanguage((int) $cookie->lang_id);
         if (!JeproshopTools::isLoadedObject($lang, 'lang_id') || !$lang->published || !$lang->isAssociatedToShop()) {
             $cookie->lang_id = null;
         }
     }
     /* Automatically detect language if not already defined, detect_language is set in Cookie::update **/
     if ((!$cookie->lang_id || isset($cookie->detect_language)) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $array = explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
         $string = $array[0];
         if (JeproshopTools::isLanguageCode($string)) {
             $lang = JeproshopLanguageModelLanguage::getLanguageByIETFCode($string);
             if (JeproshopTools::isLoadedObject($lang, 'lang_id') && $lang->published && $lang->isAssociatedToShop()) {
                 JeproshopContext::getContext()->language = $lang;
                 $cookie->lang_id = (int) $lang->lang_id;
             }
         }
     }
     if (isset($cookie->detect_language)) {
         unset($cookie->detect_language);
     }
     /* If language file not present, you must use default language file **/
     if (!$cookie->lang_id || !JeproshopTools::isUnsignedInt($cookie->lang_id)) {
         $cookie->lang_id = (int) JeproshopSettingModelSetting::getValue('default_lang');
     }
     $iso = JeproshopLanguageModelLanguage::getIsoById((int) $cookie->lang_id);
     //@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');
     return $iso;
 }