[英]SMARTY - stemmings - number of products (Prestashop)
I've got the following problem. 我有以下问题。 I'm making a shop in Prestashop CMS, which uses Smarty template engine.
我正在使用Smarty模板引擎的Prestashop CMS开店。 So there's a sentence, displaying a number of products.
所以有一句话,展示了许多产品。 Now - in english language it's simple - you can make it like that:
现在-用英语讲的很简单-您可以这样:
{l s='Cart contains'} {$productNumber} {if $productNumber == 1}{l s='product'}{else}{l s='products'}{/if}
But this shop is made in polish language - and there starts the problem. 但是这家店是用波兰语制作的,这开始出现问题。 It's much more complicated.It's like this:
它要复杂得多,就像这样:
So - how to write a smarty condition for this ? 那么,如何为此写一个聪明的条件呢?
Thanks 谢谢
I would say the logic required here is verbose enough and possibly reused enough to warrant a plugin. 我要说的是,这里所需的逻辑很冗长,并且可能足够重复使用以保证插件可用。
function smarty_modifier_nb_products_to_str($nbProducts){
if($nbProducts > 1){
$numbers = str_split((string) $nbProducts);
return count(array_intersect($numbers, array('2','3','4'))
? 'produkty'
: 'produktów';
} else {
return 'produkt';
}
}
With usage like: 用法如下:
{l s='Cart contains'} {nb_products_to_str($productNumber)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.