Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

'/helper\(\\\'([a-z_]+)\\\'\)-\>__\([\s]*([\'|\\\"])(.*?[^\\\\])\\2.*?\)/'

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

'/\$this-\>__\([\s]*([\'|\\\"])(.*?[^\\\\])\\1.*?\)/'

And for the XML files, just load the file as an xml object and then xpath the elements with the attribute translate.
[Edit]
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.

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

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 ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top