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?
4 Answers
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
-
1Thanks for the Grep, was trying to format something like that :) Commented Aug 5, 2013 at 20:53
-
Thanks. See the update which makes the output into a CSV with two columns. Commented Aug 5, 2013 at 21:07
-
-
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. Commented Aug 6, 2013 at 11:15
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'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. Commented Aug 6, 2013 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 ;-)