Are there any tools for generating a csv file for translations of a module? I.e. detecting calls to __() within a module and outputting the information into a csv ready to be used as a translation file for the module?


You can use a simple* GREP of your template files:

> grep "__\(.*?\)" -Roh . | sed "s/__([\"']//" | sed "s/[\"'].*//g" | sort | uniq

This will output a list of unique phrases - such as (ran against /app/design/frontend/base/default/templates/):

You have not tagged any products yet.
You have placed no orders yet.
You have placed no orders.
You have placed no products yet.

This will get you 80% of the way there but now you'll need to do the following:

  • This will return results for translations that are unquoted or are a direct translation of a variable, E.g. $this->__($title) - these will need to be removed and handled manually.
  • You will need to copy this content into a second column, comma delimitted. I've gone to the trouble of adding the sed command onto the grep above so that it outputs all in one go:

    > grep "__\(.*?\)" -Roh . | sed "s/__([\"']//" | sed "s/[\"'].*//g" | sort | uniq | sed "s/\(.*\)/\"\1\",\"\1\"/"

* LOL this isn't terribly simple I guess

| improve this answer | |
  • 1
    Thanks for the Grep, was trying to format something like that :) – Sander Mangel Aug 5 '13 at 20:53
  • Thanks. See the update which makes the output into a CSV with two columns. – philwinkle Aug 5 '13 at 21:07
  • Awesome, deserves a +1 :) – Sander Mangel Aug 5 '13 at 21:12
  • In the absence of any formalised tools this was going to be my approach. I guess I could also create an xml parser to extract the translatable elements from the config files. I'm just surprised nobody seems to have created a toolset for this yet. – Peter O'Callaghan Aug 6 '13 at 11:15

Here are some regular expressions that might help.
This should match Mage::helper('some_helper')->__('Some text')


This should match $this->__('Some Text')


And for the XML files, just load the file as an xml object and then xpath the elements with the attribute translate.
I've recently put together an extension that should identify the translatable texts in a module and generate the csv file for it. Check it out.

| improve this answer | |

No answer but a suggestion if that's ok.

Trying to make good translations without seeing the context around that phrase or word will be extremely hard.

I suggest trying to find a basic translation set and then go from there. You can use the 'Inline translations' from the backend to see what parts in the webshop are translatable

| improve this answer | |
  • I'm just creating a base translation file (i.e. en_US) rather than actually create a translation to another language. So the context doesn't really matter for my use case. – Peter O'Callaghan Aug 6 '13 at 11:12

I used notepad++, opened all files and subfolders of the plugin in it.

Pressed CTRL + F and searched for __( and pressed search in all documents and then went over them all and copied them into an csv.

However you put it, it's going to be a lot of work ;-)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.