CakePHP 3,国际化/翻译中的变量

CakePHP 3, variables in Internationalization / translation

我想在一些翻译文本中使用变量,但我不知道如何让它工作。将不胜感激。

我最理想的情况:

在我的页面视图中:

<?= __("welcome_message", ['John']) ?> // 或一些变体

在我的 /en/default.po 文件中

msgid "welcome_message"
msgstr "Welcome {1}, step in and have some fun!"

简而言之,如何在翻译文本中使用变量?谢谢

在您的视图中使用它,args 作为数组传输到翻译函数,{0} 获取传入 args

的数组索引 0 处的元素
<?= __("Welcome {0}", ['John']) ?>

您还可以使用此语法:将变量作为独立参数传递给函数

<?= __("Welcome {0}", 'John') ?>

Using Variables in Translation Messages