Magento : How add translation ability into cms page or static block ?

As we all know magento have multi-language store. Magento use following syntax in .pthml to make text translate to multi-language which is like this :

    <?php   echo $this->__('text to translate'); ?>

OR

    <?php   echo Mage::helper('ModuleName')->__('text to translate');  ?>

But text written in cms page or static block have not translation ability.
To make cms page or static block text compatible with translation ability we need to do some extra coding work which is like this:

We can use following directive in cms page or static block

{{translate text="text to translate"}} 

To make it working in cms page or static block we need to add directive function in magneto code as show in following steps.

1. Go to app/code/core/Mage/Core/Model/Email/Template/ and download Filter.php file

2. open Filter.php and add following function after function mediaDirective(), found at approximate Line : 280


public function translateDirective($construction)
{
	$params = $this->_getIncludeParameters($construction[2]);
	$text = $params['text'];
        return Mage::helper('page')->__($text);
} 

3. Save file.

4. Next upload Filter.php in new custom location : app/code/local/Mage/Core/Model/Email/Template/

5 Now you can easily use following directive in any cms page or static block.

{{translate text="text to translate"}} 

6. Done. :)

Comments

Muhammad Shuja 05-06-2012, 17:47

I am trying to step in magento. Can you guide me that where we have to place this code

{{translate text=”text to translate”}}

I will be very thankful to you.

Reply
Jagdeep Banga 05-06-2012, 18:50

Hi Muhammand,

You need to place this code in CMS page and Static Block.

Login into Magento admin and then from top navigation go to CMS->Page or CMS->Static Block
from list of rows there select your desire page or static block and place there this code.

You also need to set translate “text name” in your custom .csv ( app/locale/lanuage_name/lannguage_name.csv ) file also.

Reply
Alexander 28-06-2012, 15:59

Hello!

Very helpful post! Exactly what I was looking for. Thanks a lot!

However it seems not to work with strings translated in theme’s translate.csv files

Did I miss something?

Reply
Jagdeep Banga 01-07-2012, 12:11

Hi Alexander,

Can you please let me know in detail which steps you applied.
you can mail me on banga.jagdeep@gmail.com

Reply
Brian SHEN 02-05-2013, 18:59

Hi, Mr. Banga,

I would like to translate description only. I did step 1/2/3/4, for number 5, I put {{translate text=”text to translate”}} in front of home page contents first, but it still show the same as as “{{translate text=”text to translate”}} “, could you please help me out? This is very important to me. do you also provide other paid service to set up a website since from what I saw, you did get talent on computer programming. I am building up business for global trading but everything is in start point. Thanks. My email is Brian.shen@me.com

Reply
Jagdeep Banga 06-05-2013, 10:23

Hi Brian,

I sent you mail, check your inbox. if you have still problem then come back to me again.
Thanks

Reply
Volvox 17-08-2012, 20:28

It works! Great job! This should be part of Magento.

Reply
Aamir 14-09-2012, 15:41

This was a massive help today in clearing up some of the basic logic working behind the scenes. A definite bookmark. Thanks

Reply
Pradeep 19-10-2012, 16:34

Thanks a lot. It was helpful. Can you help me how to translate links in CMS??

Ex: {{translate text=”Go back to the previous page.”}}

This is not working for me… How to show this in customer.csv??? I think I missed something… Please help…

Reply
cheap windows 7 key 29-01-2013, 16:28

Definitely believe that which you said. Your favorite justification appeared to be on the net the simplest thing to be aware of. I say to you, I definitely get annoyed while people think about worries that they plainly don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people can take a signal. Will likely be back to get more. Thanks

Reply
Gemma 26-02-2013, 18:05

Hi,

This is exactly what I was looking for. Thanks a lot! But I don´t understand properly how it works. I have upload the new Filter.php with that new function in that new location but I don´t know where I have to place this code:

{{translate text=”text to translate”}}

For example:

I want to translate my footer links from Spanish to English. I have a static block called Footer Links with this code:

Quiénes somos
 
Condiciones de venta
 
Política de privacidad
 
Contacta

¿How I have to use {{translate text=”text to translate”}} code in this case?

Thanks in advance.

Reply
xtreme n reviews 11-03-2013, 17:40

I read this post fully about the comparison of most recent
and preceding technologies, it’s amazing article.

Reply
does ageless male work 15-03-2013, 03:45

I’d like to thank you for the efforts you have put in writing this site. I am hoping to view the same high-grade blog posts by you in the future as well. In truth, your creative writing abilities has motivated me to get my very own blog now ;)

Reply
Peter Svegrup 21-03-2013, 13:35

Morning!

Just wanted to say that you are an absolute champ for sharing the above tip! I’m working with quite a few multi store view clients and this is saving me so much time on some of the static menus for example!!

Big thanks again :)

Peter

Reply
salefashion 17-05-2013, 06:39

2…

This article made me feel shines. After doing some reading of this article, I inspired a lot. I will pay more attention to your blog. I hope everyone like me heregains happy, reap moved….

Reply

Leave a Reply



seven − five =