我想更改 magento 中的搜索图像。在 magento 中搜索时,图像名称为 btn_search.gif。现在它从皮肤/前端/默认/默认/图像中获取图像。文件是/app/design/frontend/default/default/template/catalogsearch/form.mini.phtml ,其中将此标签提到为
<input id="search-button" type="image" src="<?php echo $this->getSkinUrl('images/btn_search.gif') ?>" alt="<?php echo $this->__('Search') ?>" />
我检查了代码,发现我们可以将语言环境作为 _type 传递给
<input id="search-button" type="image" src="<?php echo $this->getSkinUrl('images/btn_search.gif', array('_type'=>'local')) ?>" alt="<?php echo $this->__('Search') ?>" />
但是当我检查代码时,这只会在语言环境目录中检查该文件是否存在于该语言环境中。如果存在,那么它将拍摄皮肤图像。我想使用该区域设置图像而不是该皮肤图像。
因此,当我单击法国商店时,我得到了在/app/design/frontend/default/default/locale/fr_FR/images/btn_search.gif 中设置的图像
我检查了/app/code/core/Mage/Core/Model/Design/Package.php 中 getSkinUrl 的代码。我发现他检查文件的区域设置,但它返回皮肤 url。
是否有返回语言环境 url 的方法?
最佳答案
我得到了答案
这就是我如何使按钮语言(区域设置)依赖于 magento commerce
我从主页上的迷你搜索表单开始。该表单的搜索图像按钮定义在
/app/design/frontend///template/catalogsearch/form.mini.phtml
在该文件中,我更改了以下行
<input type="image" src="<?php echo $this->getSkinUrl('images/btn_mini_search.gif') ?>" alt="<?php echo $this->__('Search') ?>"/>
至
<input type="image" src="<?php echo $this->getSkinUrl('images/btn_mini_search_'.$this->__('_LOCALE_BUTTON_').'.gif') ?>" alt="<?php echo $this->__('Search') ?>"/>
然后我将 _LOCALE_BUTTON_ 的翻译添加到所有语言环境的 translate.csv 文件中: /app/design/frontend///locale//translate.csv:
即 区域设置 en_GB:_LOCALE_BUTTON_,en_GB 区域设置 nl_NL:_LOCALE_BUTTON_,nl_NL
对于每个翻译,请确保/skin/frontend///images/目录中有可用的区域设置后缀按钮图像文件:
即 btn_mini_search_en_GB.gif btn_mini_search_nl_NL.gif
我认为您还可以通过将上面提到的行更改为来将 _LOCALE_BUTTON_ 翻译为表示文件夹:
<input type="image" src="<?php echo $this->getSkinUrl('images/locale/'.$this->__('_LOCALE_BUTTON_').'/btn_mini_search.gif') ?>" alt="<?php echo $this->__('Search') ?>"/>
但是您需要保存区域设置后缀按钮图像文件,如下所示: /skin/frontend///images/locale/en_GB/btn_mini_search.gif 和 /skin/frontend///images/locale/nl_NL/btn_mini_search.gif
我自己没有测试过最后一种方法,但我看不出它有任何不起作用的理由。
我也一直在考虑用常规的“搜索”字符串替换 _LOCALE_BUTTON_ 值(不推荐!!) 此方法的优点是,您不需要向 translate.csv 文件添加单独的翻译,但您会面临某些翻译对于多个语言环境可能相似的风险(重复键)。除此之外,当翻译中使用非 ascii/utf-8 字符时,它可能会导致问题,但这取决于您使用的操作系统/文件系统。
关于php - 如何在magento中更改区域设置基础上的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2019273/