I have a question that I'm sure has a simple solution, and if my brain worked properly these days I'd be able to find it either online or somewhere in the archives... But I can't, so here goes...
I need to parse an entire project through a regex, and produce some formatted output. The regex is quite simple, and the reason is to create a 'translation' file. I have a huge project where I've used the wordpress-style convention (which in turn is based on the gettext style convention) of translating strings, namely passing them to the __() function (this is all in php). I'm not using gettext, i've just wrapped my own code around that function (which is why i'm using __() instead of _() )
This function at the moment simply returns the input as output (since all the text strings are in english, and I haven't really translated anything yet so my translation files are empty). What I want is to parse all of my code for /__(['"](.*)['"])/ and some variations thereof, and produce a line-separated list of strings that need to be translated. I'd like to make this an automated process, because this is an ongoing project and i'd like to refresh the to-be-translated strings file frequently.
I believe poedit already does something like this, but attempting to get my head around .po and .mo files at this point just gave me a migraine (nb: if someone knows of a good, step-by-step 'for dummies' tutorial for this stuff, I'd appreciate it).
Any ideas?
Constantinos Neophytou
As a followup, I guess what I'm looking for is something along the lines of what xgettext does, but directory-based instead of file- based, and also the ability to provide my own custom 'keywords' (I also use this in smarty templates, in the form of {'text'|__} ). Something like pybabel, but for php... I'm starting to wonder how complicated this should be, as it sounds like a fairly easy task...
On 9 Sep 2007, at 18:13, Constantinos Neophytou ♎ wrote:
I have a question that I'm sure has a simple solution, and if my brain worked properly these days I'd be able to find it either online or somewhere in the archives... But I can't, so here goes...
I need to parse an entire project through a regex, and produce some formatted output. The regex is quite simple, and the reason is to create a 'translation' file. I have a huge project where I've used the wordpress-style convention (which in turn is based on the gettext style convention) of translating strings, namely passing them to the __() function (this is all in php). I'm not using gettext, i've just wrapped my own code around that function (which is why i'm using __() instead of _() )
This function at the moment simply returns the input as output (since all the text strings are in english, and I haven't really translated anything yet so my translation files are empty). What I want is to parse all of my code for /__(['"](.*)['"])/ and some variations thereof, and produce a line-separated list of strings that need to be translated. I'd like to make this an automated process, because this is an ongoing project and i'd like to refresh the to-be-translated strings file frequently.
I believe poedit already does something like this, but attempting to get my head around .po and .mo files at this point just gave me a migraine (nb: if someone knows of a good, step-by-step 'for dummies' tutorial for this stuff, I'd appreciate it).
Any ideas?
Constantinos Neophytou
On 9 Sep 2007, at 10:48, Constantinos Neophytou ♎ wrote:
I have a huge project where I've used the wordpress-style convention (which in turn is based on the gettext style convention) of translating strings
I would say your best option is to use poedit, as you say it has the parsing built in already. A simple google search found me
http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites- using-gettext/
I’m sure there are others.
The other option would be to modify your PHP function (i.e. __() ) to do the output to the file and then browse around your site to invoke them.
Unfortunately, I'm unable to get poedit to work properly on my system (keeps telling me it doesn't find anything), and also doesn't really work for the smarty templates...
modifying my php function could be an option, but not the automated method i'm looking for... but thanks for the feedback, that link will come in handy at some point!
On 9 Sep 2007, at 20:00, Ciarán Walsh wrote:
I would say your best option is to use poedit, as you say it has the parsing built in already. A simple google search found me
http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites- using-gettext/
I’m sure there are others.
The other option would be to modify your PHP function (i.e. __() ) to do the output to the file and then browse around your site to invoke them.
On 9/9/07, Constantinos Neophytou ♎ constantinos@neophytou.net wrote:
I need to parse an entire project through a regex...
Take a look at the "Grep in Project" command:
http://henrik.nyh.se/2007/06/grep-in-project-command-for-textmate
If can be easily modified to suit your needs, and it spits results on a format you can copy and paste on another document.
Also, good old commandline grep may be just what you're looking for...
On 9 Sep 2007, at 20:12, Ale Muñoz wrote:
Take a look at the "Grep in Project" command:
http://henrik.nyh.se/2007/06/grep-in-project-command-for-textmate
If can be easily modified to suit your needs, and it spits results on a format you can copy and paste on another document.
Thanks, that helped. I made a bash script that outputs the grep data, and I have the find/replace strings for TextMate's regular expression match.. What's the best way to combine the two, i.e. run the bash script, and then pipe the output in a regex find/replace, and output to a file? I'm guessing my options are either a complicated macro (don't know how to output to a file with this method, if even possible), or a Command... which I think would be preferable, but then how would I go about executing the find/replace inside the command?
Constantinos Neophytou