Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
b744feb5
Commit
b744feb5
authored
Apr 22, 2017
by
Ad Schellevis
Committed by
GitHub
Apr 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1533 from kekek2/master
Setting locale in ApiControllerBase
parents
02cdb61a
57e6e8d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
20 deletions
+39
-20
ApiControllerBase.php
...e/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php
+1
-0
ControllerBase.php
...ense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
+5
-20
ControllerRoot.php
...ense/mvc/app/controllers/OPNsense/Base/ControllerRoot.php
+33
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php
View file @
b744feb5
...
...
@@ -91,6 +91,7 @@ class ApiControllerBase extends ControllerRoot
{
// disable view processing
set_error_handler
(
array
(
$this
,
'APIErrorHandler'
));
self
::
setLocale
(
self
::
getLangEncode
());
}
/**
...
...
src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
View file @
b744feb5
...
...
@@ -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).
...
...
src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerRoot.php
View file @
b744feb5
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment