Admin language switcher. Enabled only if multilang is active. Allows to switch pages content to the desired language

This commit is contained in:
Flavio Copes
2015-08-14 19:12:04 +02:00
parent dd41509c79
commit ecfc77df1c
4 changed files with 53 additions and 2 deletions

View File

@@ -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;
}
}
/**

View File

@@ -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.
*

View File

@@ -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
ADD_ACCOUNT: Aggiungi utente
SWITCH_LANGUAGE: Cambia lingua

View File

@@ -78,6 +78,21 @@
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
<a class="button" href="#modal" data-remodal-target="modal"><i class="fa fa-plus"></i> {{ "PLUGIN_ADMIN.ADD_PAGE"|tu }}</a>
<a class="button" href="#modular" data-remodal-target="modular"><i class="fa fa-plus"></i> {{ "PLUGIN_ADMIN.ADD_MODULAR"|tu }}</a>
{% if admin.multilang %}
<div class="button-group">
<button type="button" class="button dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-language"></i> {{ "PLUGIN_ADMIN.SWITCH_LANGUAGE"|tu }} &nbsp; <i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu">
{% for language in admin.languages_enabled %}
<li><a class="button" href="{{ base_url_relative }}{{ theme.slug }}/pages/task{{ config.system.param_sep }}switchlanguage/lang{{ config.system.param_sep }}{{language}}"><i class="fa fa-fw fa-plus"></i> {{language}}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{% elseif mode == 'edit' %}
<a class="button" href="{{ base_url }}/pages"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
{% if exists %}