We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to use placeholders with the translate Adapter?

Hello,

I'm trying to use the \Phalcon\Translate\Adapter\NativeArray with placeholders like in this simple example:

$t = new \Phalcon\Translate\Adapter\NativeArray(['content' => ['test' => 'Hello #name#!']]);
var_export($t->_('test', ['name' => 'John Doe']));

But the translated string is Hello #name#! and not as expected Hello John Doe! .

According to the abstract Adapter all strings sourrounded with # should be repalceable.

What am I doing wrong?



51.2k
edited May '15
Use: %name%
let translation = str_replace("%" . key . "%", value, translation);