我能够使用 volt 模板在 Phalcon 中添加多语言支持。
但我无法以伏特访问 phalcon 多维 NativeArray。
这是我的 getTranslation 函数:
private function _getTranslation()
{
global $config;
if ( isset($config[$_SERVER['HTTP_HOST']]['language']) ) {
$language = $config[$_SERVER['HTTP_HOST']]['language'];
} else if ( $this->session->get('auth') ) {
$language = "pt";
} else {
//Ask browser what is the best language
$language = $this->request->getBestLanguage();
}
//Check if we have a translation file for that lang
if (file_exists(__DIR__ . "/../translations/".$language.".php")) {
require __DIR__ . "/../translations/".$language.".php";
} else {
// fallback to some default
require __DIR__ . "/../translations/en-US.php";
}
//Return a translation object
return new \Phalcon\Translate\Adapter\NativeArray(array(
"content" => $messages
));
}
然后我设置变量:
$this->view->setVar("t", $this->_getTranslation());
这将加载一个翻译文件,如下所示:
$messages = array(
"pages" => array(
"index" => array(
"title" => "CREATE YOUR ACCOUNT TODAY",
"call_to_action" => "Join Now!",
"search_title" => "Find:",
"search_option" => "I Want To:",
"search_type" => "Type:",
"search_where" => "Located On:",
"search_button" => "GO",
)
);
在伏特模板中,我想访问类似
$t['pages']['index']['call_to_action']
其中伏特可能是:
<div class="call_to_action">{{ t._('pages').('index').('call_to_action') }}</div>
但这不起作用!
有什么方法可以访问 volt 模板中的 NativeArray 多维元素?