Grav\Plugin\Admin\AdminController::taskSwitchlanguage PHP Method

taskSwitchlanguage() protected method

Switch the content language. Optionally redirect to a different page.
protected taskSwitchlanguage ( )
    protected function taskSwitchlanguage()
    {
        $data = (array) $this->data;
        if (isset($data['lang'])) {
            $language = $data['lang'];
        } else {
            $language = $this->grav['uri']->param('lang');
        }
        if (isset($data['redirect'])) {
            $redirect = 'pages/' . $data['redirect'];
        } else {
            $redirect = 'pages';
        }
        if ($language) {
            $this->grav['session']->admin_lang = $language ?: 'en';
        }
        $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info');
        $admin_route = $this->admin->base;
        $this->setRedirect('/' . $language . $admin_route . '/' . $redirect);
    }