简体   繁体   English

SMARTY-茎类-产品数量(Prestashop)

[英]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: 它要复杂得多,就像这样:

  1. For 1 product you have one word - "produkt" 对于1个产品,您只有一个词-“ produkt”
  2. For 2,3 and 4 products and every number that contains those numbers (like 22,23,24,32,33,34,152,153,154,242,243,244, etc.) another word - "produkty" 对于2,3和4产品以及包含这些数字的每个数字(例如22,23,24,32,33,34,152,153,154,242,243,244等),另一个词是“ produkty”
  3. For everything above 4 (except those numbers in point 2) third word - "produktów" 对于高于4的所有内容(第2点中的数字除外),第三个单词-“produktów”

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM