function languageSetup() { // check for activated language support if (!c::get('lang.support')) { return false; } // get the available languages $available = c::get('lang.available'); // sanitize the available languages if (!is_array($available)) { // switch off language support c::set('lang.support', false); return false; } // get the raw uri $uri = uri::raw(); // get the current language code $code = a::first(explode('/', $uri)); // try to detect the language code if the code is empty if (empty($code)) { if (c::get('lang.detect')) { // detect the current language $detected = str::split(server::get('http_accept_language'), '-'); $detected = str::trim(a::first($detected)); $detected = !in_array($detected, $available) ? c::get('lang.default') : $detected; // set the detected code as current code $code = $detected; } else { $code = c::get('lang.default'); } // go to the default homepage go(url(false, $code)); } // http://yourdomain.com/error // will redirect to http://yourdomain.com/en/error if ($code == c::get('404')) { go(url('error', c::get('lang.default'))); } // validate the code and switch back to the homepage if it is invalid if (!in_array($code, c::get('lang.available'))) { go(url()); } // set the current language c::set('lang.current', $code); // mark if this is a translated version or the default version $code != c::get('lang.default') ? c::set('lang.translated', true) : c::set('lang.translated', false); // load the additional language files if available load::language(); }