开发者

How to change image on locale base in magento?

开发者 https://www.devze.com 2022-12-15 13:47 出处:网络
I want to change search image in magento. On search in magento the image name is btn_search.gif. Right now it take image from skin/frontend/default/default/images. And the file is /app/design/frontend

I want to change search image in magento. On search in magento the image name is btn_search.gif. Right now it take image from skin/frontend/default/default/images. And the file is /app/design/frontend/default/default/template/catalogsearch/form.mini.phtml where mention this tag as

<input id="search-button" type="image" src="<?php echo $this->getSkinUrl('images/btn_search.gif') ?>" alt="<?php echo $this->__('Search') ?>" />

I check the code and i found that we can pass locale as _type in this as

<input id="开发者_如何学Pythonsearch-button" type="image" src="<?php echo $this->getSkinUrl('images/btn_search.gif', array('_type'=>'local')) ?>" alt="<?php echo $this->__('Search') ?>" />

But when i check the code this will just check in locale directory that this file exist in that locale or not. If this exist then it will take skin image. I want to use that locale image instead of that skin image.

So when i click on french store i get the image which is i set in /app/design/frontend/default/default/locale/fr_FR/images/btn_search.gif

I check the code for getSkinUrl in /app/code/core/Mage/Core/Model/Design/Package.php. And i found that he check locale for file but it return skin url.

Is there any method which return locale url ?


I got the answer

This is how I have made the buttons language (locale) dependent within magento commerce

I started with the mini-search form on the homepage. The search image button for that form is defined in

/app/design/frontend///template/catalogsearch/form.mini.phtml

In that file i’ve changed the following line

<input type="image" src="<?php echo $this->getSkinUrl('images/btn_mini_search.gif') ?>" alt="<?php echo $this->__('Search') ?>"/>

to

<input type="image" src="<?php echo $this->getSkinUrl('images/btn_mini_search_'.$this->__('_LOCALE_BUTTON_').'.gif') ?>" alt="<?php echo $this->__('Search') ?>"/>

Then I added the translation for _LOCALE_BUTTON_ to all the the locale translate.csv files: /app/design/frontend///locale//translate.csv:

I.e. Locale en_GB: _LOCALE_BUTTON_,en_GB Locale nl_NL: _LOCALE_BUTTON_,nl_NL

For each translation make sure you have the locale suffix button image files available in the /skin/frontend///images/ directory:

I.e. btn_mini_search_en_GB.gif btn_mini_search_nl_NL.gif

I think you can also make the translation for _LOCALE_BUTTON_ to represent a folder by changing the line mentioned above to:

<input type="image" src="<?php echo $this->getSkinUrl('images/locale/'.$this->__('_LOCALE_BUTTON_').'/btn_mini_search.gif') ?>" alt="<?php echo $this->__('Search') ?>"/>

but then you need to save the locale suffix button image files like this: /skin/frontend///images/ locale/en_GB/btn_mini_search.gif and /skin/frontend///images/ locale/nl_NL/btn_mini_search.gif

I haven’t tested the last method myself, but I don’t see any reasons why it shouldn’t work.

I’ve also been thinking about replacing the _LOCALE_BUTTON_ value with the regular ‘Search’ string (Not recommended!!) The advantage of this method is that you don’t need to add seperate translations to the translate.csv files but then you run the risk that certain translations can be similar for multiple locales (duplicate keys). Besides that it can lead to issues, when non-ascii/utf-8 characters are used in the translations, but that depends on the operating/file system you are using.

0

精彩评论

暂无评论...
验证码 换一张
取 消