I successefully added multilanguage abilities to WEB in Phalcon using the volt template.
But how can I use that translation within controller so I can translate flash messages.
My Base Controller:
protected function _t() {
// Get language code
if($this->session->has("lg")) {
$language = $this->session->get("lg");
} else {
// Ask browser what is the best language
$language = $this->request->getBestLanguage();
}
// Check if we have a translation file for that language
if(file_exists(APP_PATH . "app/languages/".$language.".php")) {
require APP_PATH . "app/languages/".$language.".php";
} else {
// Fallback to default language
require APP_PATH . "app/languages/en.php";
}
// Return a translation object
return new \Phalcon\Translate\Adapter\NativeArray(array(
"content" => $t
));
}
Then I put that inside view like this:
$this->view->setVar("t", $this->_t());
Inside view I can use translation like:
<?php echo $t->_t('hello') ?>
But how can I use that inside other controllers that extends BaseController
class IndexController extends BaseController {
...
$this->flashSession->error('HOW TO ADD TRANSLATION HERE');
...
}