2

我需要在 Prestashop 中传递一个带有翻译字符串的变量。在后端可以这样做

sprintf($this->l('The number is %1$d'), $number);

但是我需要在使用 SMARTY 时在前端执行此操作?有人帮我吗?

4

3 回答 3

7

像这样的东西:

{l s='The number is %1$d' sprintf=$number}
于 2013-01-29T10:12:03.720 回答
2

1 - 在 PrestShop v1.7.4 上使用@skiplecariboo 回答{l s='The number is %1$d' sprintf=$number}我得到:

可捕获的致命错误:传递给 PrestaShopBundle\Translation\TranslatorComponent::trans() 的参数 2 必须是数组类型,给定字符串,在第 210 行的 /vagrant/httpdocs/config/smartyfront.config.inc.php 中调用并定义

2 - 使用官方 3rd 方模块翻译方法 {l s='The number is %1$d' sprintf=$number mod='my_module'},我得到同样的错误:

可捕获的致命错误:传递给 PrestaShopBundle\Translation\TranslatorComponent::trans() 的参数 2 必须是数组类型,给定字符串,在第 210 行的 /vagrant/httpdocs/config/smartyfront.config.inc.php 中调用并定义

3 - 使用官方原生模块翻译方法 {l s='The number is %1$d' sprintf=$number d='Modules.my_module'},我得到:

无法翻译 module:my_module/my_module.tpl 中的“The number is %1$d”。sprintf() 参数应该是一个数组。

所以,对我来说,解决方案是将$number变量设置为数组:

{l s='The number is %1$d' sprintf=[$number] mod='my_module'}

注意:%1$d标志是十进制的,对于一个字符串,使用%1$s:(来源

于 2018-12-28T11:07:18.273 回答
0

这就是您可以在翻译后的字符串中传递变量的方式

{l s='Comment: # %id%' mod='ayalinecomments' sprintf=['%id%' => $comment.id_ayalinecomments_comment]}

prestashop 将用我的变量 $comment.id_ayalinecomments_comment 替换 %id%

于 2018-03-13T12:32:35.600 回答