我在翻译洋红色字符串时遇到问题:
"允许购买的最小数量为 %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函数中翻译一些字符串。该函数的文档不是很有帮助(链接)
所以我希望有人知道这个字符串在哪里,这样我就可以手动覆盖它。
谢谢帕特里克
在主题文件夹中创建一个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
表。
编辑:您要查找的字符串在位于 app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
中的类Mage_CatalogInventory_Model_Stock_Item
定义
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;
}