如何翻译文本在控制器文件prestshop


How to translate text in controller file Prestashop

我覆盖了一个控制器文件(CartController)…我得到产品状态(新)我将在法国的网站成为"新"。我使用以下代码,但它不工作。我怎样才能解决这个问题呢?

/覆盖/控制器/前面/CartController.php:

[...] 
$list_product = $cart_current->getProducts();
foreach ($list_product as $index => $product){
    $product_current = new ProductCore($product['id_product'],true);
    $result['label'] = $this->l($product_current->condition); /* Translation? */
}
[...]

首先我建议像这样修复你的代码:

[...] 
$list_product = $cart_current->getProducts();
foreach ($list_product as $index => $product){
    $product_current = new Product($product['id_product'],true); // Product not ProductCore
    $result['label'] = $product_current->condition; // Translation not here in the 'controller' but we make in the 'view'
}
[...]

然后在'view' (cart.tpl/product.tpl)中:

[...]
/*
You have to comment this translations to avoid displaying. This is a workaround used also for the months.
{l s='New'} // {l s='New' mod='mymodule'} if you are in your module tpl
{l s='Used'} // Like above
*/
{l s='%s' sprintf=[$result['label']]}
[...]

最好的做法是重写classes/Cart.php, function getProducts并添加query

, p.`condition`

您可以尝试在任何模块翻译中添加'New'的翻译文本后使用以下方法

翻译:getModuleTranslation ()

代替

$ this -> l ()