代码之家  ›  专栏  ›  技术社区  ›  Patrick

在Magento中转换escapeHtml($message)变量

  •  0
  • Patrick  · 技术社区  · 10 年前

    我在翻译magento中的字符串时遇到问题:

    “允许购买的最小数量为%s。” 我尝试了不同的翻译变体,包括%d和*。

    因此,我已尝试翻译语言文件中的字符串,用于Mage_Api、Mage_Catalog和Mage_CatalogInventory。我之前已经翻译了很多字符串,但是这个字符串不想被翻译。

    所以我想手动翻译字符串,但是我遇到了一个问题。我找到了以下代码段,其中显示了消息:

    <?php if ($messages = $this->getMessages()): ?>
            <?php foreach ($messages as $message): ?>
                <p class="item-msg <?php echo $message['type'] ?>">* <?php
                 echo $this->escapeHtml($message['text']) ?></p>
            <?php endforeach; ?>
            <?php endif; ?>
    

    在呈现的HTML中,输出如下:

    <p class="item-msg error">* The minimum quantity allowed for purchase is 6.</p>
    

    所以我想,我必须在escapeHtml函数中转换一些字符串。函数的文档不是很有用( link )

    所以我希望有人知道这个字符串在哪里,所以我可以手动覆盖它。

    谢谢 帕特里克

    1 回复  |  直到 10 年前
        1
  •  1
  •   Lord Skeletor    10 年前

    在主题文件夹中创建 locale/[locale]/translate.csv 文件

    例子: app/design/frontend/package/theme/locale/en_US/translate.csv

    并粘贴此行:

    "Mage_CatalogInventory::The minimum quantity allowed for purchase is %s.","TEST The minimum quantity allowed for purchase is %s."
    

    刷新 Translations 缓存,你就完成了。如果您仍在获取旧字符串,请检查 core_translate 桌子

    编辑 : 您要查找的字符串在中定义 Mage_CatalogInventory_Model_Stock_Item 类位于 app/code/core/Mage/CatalogInventory/Model/Stock/Item.php

     if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) {
                $result->setHasError(true)
                    ->setMessage(
                        Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1)
                    )
                    ->setErrorCode('qty_min')
                    ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))
                    ->setQuoteMessageIndex('qty');
                return $result;
            }