/** * @param Config $config * @return Config */ public function merge(Config $config) { $this->config = array_replace_recursive($this->config, $config->getAll()); return $this; }
/** * @param array $cookie PHP $_COOKIE variable * @param string|boolean $fallback (optional) */ public function handleDictionary($cookie, $fallback = false) { if (count(Language::getLanguages()) > 0) { $languageCookieIndex = 'plinth-language'; $languageCookieAble = false; $languageCode = null; $this->_lang = Language::getDefault(); //Get browser language, Accept-Language overrules default language if ($this->getSetting('localeaccept') && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && count($this->config->get('language:locales')) > 0) { $regex = '/' . implode('|', $this->config->get('language:locales')) . '/'; $languageViaAccept = preg_match_all($regex, $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches); if ($languageViaAccept > 0) { $languageCode = $matches[0][0]; } } //Get get language, Get-Language overrules Accept-Language if ($this->getSetting('localeget') !== false) { $languageViaGet = $this->getRequest()->get($this->getSetting('localeget')); if ($languageViaGet !== null) { $languageCode = $languageViaGet; $languageCookieAble = true; } } //Get route language, Route-Language overrules Get-Language if ($this->getRouter()->hasRoute()) { $languageViaRequest = $this->getRouter()->getRoute()->get(Route::DATA_LANG); if ($languageViaRequest !== false) { $languageCode = $languageViaRequest; $languageCookieAble = true; } } if ($languageCode !== null) { $this->_lang = Language::validate($languageCode); if ($this->getSetting('localecookie') && $languageCookieAble) { //Save language cookie if it doesn't exist or if it's different from the previously saved one if (!isset($cookie[$languageCookieIndex]) || isset($cookie[$languageCookieIndex]) && $cookie[$languageCookieIndex] !== $this->_lang) { $cookie[$languageCookieIndex] = $this->_lang; $this->getResponse()->saveCookie($languageCookieIndex, $this->_lang); } } } if ($this->getSetting('localecookie') && isset($cookie[$languageCookieIndex]) && Language::validate($cookie[$languageCookieIndex]) && $cookie[$languageCookieIndex] !== $this->_lang) { $this->_lang = $cookie[$languageCookieIndex]; } $this->getDict()->loadLanguage($this->_lang, $this->getSetting('localetype')); if ($fallback !== false) { if (Language::validate($fallback) === $fallback) { $this->getDict()->loadLanguage($fallback, $this->getSetting('localetype'), true); } else { throw new PlinthException("Your fallback locale, {$fallback}, doesn't exist"); } } } }