What I posted above is really all there is to it. Just replace the 'require "some/file" part with the path to a php file with this in it
return array(
'some_key1' => 'Your translated text message',
'some_key2' => 'Another translated text message',
...
);
Then any time in your view, use 'echo $translator->_('some_key1');' to print out your message.
If you need it in your controller, use '$txt = $this->translator->_('some_key');'
I agree with quasipickle. I'm making a site that will be available in many different langs, so I've got one controller that looks like this, and all the others extend it
abstract class Controller extends \Phalcon\Mvc\Controller {
public function initialize() {
....
$this->setLocale()
....
}
public function setLocale() {
$lang = $this->dispatcher->getParam('lang'); //pull lang from url
$translator = new \Phalcon\Translate\Adapter\NativeArray( require "some/file/".$lang.".php" );
$this->view->setVar('translate', $this->translator);
$this->di['translator'] = $translator;
}
}
That's cool. Can you share the complete example code?