Move translate function so it's accessible from all admin parts. Correctly change $l->translate() calls to it

This commit is contained in:
Flavio Copes
2015-08-14 15:05:33 +02:00
parent e0675355e2
commit b80678c74b
3 changed files with 36 additions and 25 deletions

View File

@@ -68,6 +68,11 @@ class Admin
*/
public $user;
/**
* @var Lang
*/
protected $lang;
/**
* @var Grav\Common\GPM\GPM
*/
@@ -91,6 +96,7 @@ class Admin
$this->uri = $this->grav['uri'];
$this->session = $this->grav['session'];
$this->user = $this->grav['user'];
$this->lang = $this->grav['user']->language;
}
/**
@@ -156,7 +162,7 @@ class Admin
$l = $this->grav['language'];
$this->setMessage($l->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info');
$this->setMessage($this->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info');
// $redirect_route =$this->getLoginRedirect() ?: $this->uri->route();
$redirect_route = $this->uri->route();
@@ -604,6 +610,11 @@ class Admin
}
}
/**
* Renders phpinfo
*
* @return string The phpinfo() output
*/
function phpinfo() {
ob_start();
phpinfo();
@@ -613,4 +624,14 @@ class Admin
$pinfo = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1',$pinfo);
return $pinfo;
}
/**
* Translate a string to the user-defined language
*
* @param $string the string to translate
*/
public function translate($string) {
return $this->grav['language']->translate($string, [$this->grav['user']->authenticated ? $this->lang : 'en']);
}
}