Hi, I'm trying to create basic multi-lingual project. After studing documentation and github sample, I found very cumbersome to pass and especially use \Phalcon\Translate\Adapter\NativeArray object in view even though it's only two extra symbols in volt. Just feels wrong to me. Here is what I've come up with:
// index.volt
{{ _("main") }}
//services.php
$di->set('translate', function() {
$language = "uk";
if (file_exists("../app/messages/".$language.".php")) {
require "../app/messages/".$language.".php";
} else {
require "../app/messages/en.php";
}
return new \Phalcon\Translate\Adapter\NativeArray(array(
"content" => $messages
));
});
$volt->getCompiler()->addFunction('_', function($translateKey, $placeholders=null) use ($di) {
$t = $di->get('translate');
$str = $t->_($translateKey, $placeholders);
return $str;
});
I've spent some time debugging this peace and can't understand what's going on. $tranlateKey value in debuger is main', with a single quote at the end and placeholders not null even though as you can see nothiing was passed from the view. In browser I always get "main" without quotes. First thought that's a default behaviour if key not found in array, so I added "main'" entry to array - noting changes. Also I tried explicitly call $t method _ without placeholders parameter - no luck.
Why this code is brocken?