Commit b744feb5 authored by Ad Schellevis's avatar Ad Schellevis Committed by GitHub

Merge pull request #1533 from kekek2/master

Setting locale in ApiControllerBase
parents 02cdb61a 57e6e8d8
......@@ -91,6 +91,7 @@ class ApiControllerBase extends ControllerRoot
{
// disable view processing
set_error_handler(array($this, 'APIErrorHandler'));
self::setLocale(self::getLangEncode());
}
/**
......
......@@ -44,32 +44,17 @@ class ControllerBase extends ControllerRoot
* @param OPNsense\Core\Config $cnf config handle
* @return ViewTranslator
*/
public function getTranslator($cnf)
public function getTranslator()
{
$lang = 'en_US';
foreach ($cnf->object()->system->children() as $key => $node) {
if ($key == 'language') {
$lang = $node->__toString();
break;
}
}
$lang_encoding = $lang . '.UTF-8';
$textdomain = 'OPNsense';
$lang_encoding = self::getLangEncode();
$ret = new ViewTranslator(array(
'directory' => '/usr/local/share/locale',
'defaultDomain' => $textdomain,
'defaultDomain' => 'OPNsense',
'locale' => $lang_encoding,
));
/* this isn't being done by Phalcon */
putenv('LANG=' . $lang_encoding);
textdomain($textdomain);
bindtextdomain($textdomain, '/usr/local/share/locale');
bind_textdomain_codeset($textdomain, $lang_encoding);
self::setLocale($lang_encoding);
return $ret;
}
......@@ -211,7 +196,7 @@ class ControllerBase extends ControllerRoot
$cnf = Config::getInstance();
// set translator
$this->view->setVar('lang', $this->getTranslator($cnf));
$this->view->setVar('lang', $this->getTranslator());
$this->view->menuSystem = $menu->getItems("/ui".$this->router->getRewriteUri());
// set theme in ui_theme template var, let template handle its defaults (if there is no theme).
......
......@@ -29,6 +29,7 @@
namespace OPNsense\Base;
use OPNsense\Core\Config;
use Phalcon\Mvc\Controller;
use Phalcon\Logger\Adapter\Syslog;
use OPNsense\Core\ACL;
......@@ -47,6 +48,38 @@ class ControllerRoot extends Controller
session_write_close();
}
/**
* Get lang encoding for gettext
*/
public static function getLangEncode()
{
$lang = 'en_US';
// Set locale
foreach (Config::getInstance()->object()->system->children() as $key => $node) {
if ($key == 'language') {
$lang = $node->__toString();
break;
}
}
return $lang . '.UTF-8';
}
/**
* Set locale for gettext
*/
public static function setLocale($lang_encoding)
{
$textdomain = 'OPNsense';
/* this isn't being done by Phalcon */
putenv('LANG=' . $lang_encoding);
textdomain($textdomain);
bindtextdomain($textdomain, '/usr/local/share/locale');
bind_textdomain_codeset($textdomain, $lang_encoding);
}
/**
* get system logger
* @param string $ident syslog identifier
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment