public static function get_other_language() { $other_language = ENGLISH_STRING; if (\Fuel\Core\Lang::get_lang() == ENGLISH_STRING) { $other_language = FRENCH_STRING; } return $other_language; }
public function __construct($request) { parent::__construct($request); // Using Native PHP Session. If there's ANY problem with those sessions (bug, security breach, etc), see Sébastien Juroszek. session_start(); // Taking the lang frm the URL and removing it from the URL $this->lang = $request->method_params[0]; unset($request->route->segments[2]); $request->route->segments = array_values($request->route->segments); unset($request->route->method_params[0]); $request->route->method_params = array_values($request->route->method_params); unset($request->method_params[0]); $request->method_params = array_values($request->method_params); // Setting the current language if (Lang::get_lang() != $this->lang) { Config::set("language", $this->lang); } }
public static function switch_language($other_lang) { $url = \Fuel\Core\Router::get('home_en') . '/'; $switch_page = ''; $params = array(); $current_lang = \Fuel\Core\Lang::get_lang(); // Loop through routes foreach (\Fuel\Core\Router::$routes as $key => $route) { // If there's segments in route (weird, but that tells us that it's the current route...!) if (count($route->segments) > 0) { if (strpos($key, '_' . $current_lang, strlen($key) - strlen('_' . $current_lang)) !== false) { $switch_page = str_replace('_' . $current_lang, '_' . $other_lang, $key); $params = $route->method_params; } $url = rtrim(\Fuel\Core\Router::get($switch_page, $route->named_params), "/") . "/"; foreach ($params as $param) { if ($param != $current_lang && $param != $other_lang) { $url .= $param . '/'; } } } } return $url; }