【问题标题】:How to change image on locale base in magento?如何在magento中更改基于语言环境的图像?
【发布时间】:2010-01-07 09:20:05
【问题描述】:

我想在 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 在 this as 中传递

<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。

有没有什么方法可以返回locale url?

【问题讨论】:

    标签: php magento


    【解决方案1】:

    我得到了答案

    这就是我在 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

    我认为您也可以通过将上述行更改为:

    <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 字符时,它可能会导致问题,但这取决于您使用的操作/文件系统。

    【讨论】:

      猜你喜欢
      • 2018-07-09
      • 1970-01-01
      • 2013-04-27
      • 2023-03-24
      • 1970-01-01
      • 2012-08-18
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      相关资源
      最近更新 更多