diff --git a/classes/admin.php b/classes/admin.php index add5dd3c..24f5568e 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -92,11 +92,30 @@ class Admin $this->base = $base; $this->location = $location; $this->route = $route; - $this->uri = $this->grav['uri']; $this->session = $this->grav['session']; $this->user = $this->grav['user']; $this->lang = $this->grav['user']->language; + + + $language = $this->grav['language']; + if ($language->enabled()) { + $this->multilang = true; + $this->languages_enabled = $this->grav['config']->get('system.languages.supported', []); + + //Set the currently active language for the admin + $language = $this->grav['uri']->param('lang'); + if (!$language) { + $language = $this->session->admin_lang; + } + $this->grav['language']->setActive($language ?: 'en'); + + + } else { + $this->grav['language']->setActive('en'); + $this->multilang = false; + } + } /** diff --git a/classes/controller.php b/classes/controller.php index 75919cd3..293b660e 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -1028,6 +1028,21 @@ class AdminController return true; } + protected function taskSwitchlanguage() { + $language = $this->grav['uri']->param('lang'); + + if ($language) { + $this->grav['session']->admin_lang = $language ?: 'en'; + } + + $redirect = 'pages'; + + $this->admin->setMessage('Successfully switched language', 'info'); + $this->setRedirect($redirect); + + return true; + } + /** * Prepare and return POST data. * diff --git a/languages.yaml b/languages.yaml index 4ca30a52..1e0e1c57 100644 --- a/languages.yaml +++ b/languages.yaml @@ -130,6 +130,7 @@ en: SYSTEM: System USER: User ADD_ACCOUNT: Add Account + SWITCH_LANGUAGE: Switch Language es: ADMIN_BETA_MSG: ¡Está es una versión Beta! Utilízala bajo tu propio riesgo... @@ -282,4 +283,5 @@ it: INFO: Info SYSTEM: Sistema USER: Utente - ADD_ACCOUNT: Aggiungi utente \ No newline at end of file + ADD_ACCOUNT: Aggiungi utente + SWITCH_LANGUAGE: Cambia lingua \ No newline at end of file diff --git a/themes/grav/templates/pages.html.twig b/themes/grav/templates/pages.html.twig index e2f964e2..f1cdd741 100644 --- a/themes/grav/templates/pages.html.twig +++ b/themes/grav/templates/pages.html.twig @@ -78,6 +78,21 @@ {{ "PLUGIN_ADMIN.BACK"|tu }} {{ "PLUGIN_ADMIN.ADD_PAGE"|tu }} {{ "PLUGIN_ADMIN.ADD_MODULAR"|tu }} + + {% if admin.multilang %} +
+ + +
+ {% endif %} + + {% elseif mode == 'edit' %} {{ "PLUGIN_ADMIN.BACK"|tu }} {% if exists %}