I am looking for a shell script which scans a direcotry and all its subdirectories for .php and .phtml files. Within these files, I am looking for $this->translate('') statements (also $this->view->translate('')) and I want to save the content of these statements in a textfile.
The problem is, that there are several different types of this statements:
- $this->translate('Single Quotes') // I need: Single Quotes
- $this->translate("Double Quotes") // I need: Double Quotes
- $this->translate('Single quotes with %1$s placeholders', $xy) // I need: Single quotes with %1$s placeholders
- $this->translate("Double quotes with %1\$s", $xy) // I need: Dobule quotes with %1$s
- $this->view->translate('With view') // I need: With view
- $this->view->translate("With view 2") // I need: With view 2
- $this->translate('Single Quotes with "Doubles"') // I need: Single Quotes with "Doubles"
- $this->translate("Double Quotes with 'Singles') // I need: Double Quotes with 'Singles'
I have already programmed a script and a guy from starmind.com sent me the following lines:
echo -n > give_me_your_favorite_outfile_name.txt
for i in `find . -iname '*php' `
do
echo -n "Processing $i ..."
# echo " +++++++ from $i ++++++++" >> give_me_your_favorite_outfile_name.txt
cat $i | sed -n -e '/->translate(*/p' | sed -e 's/\(.*->translate(.\)\([a-z A-Z \d092\d039\d034]*\)\(.*\)/\2/g' | sed -e 's/\(.*\)\(\d039\)/\1/g' | sed -e 's/\(.*\)\(\d034\)/\1/g' >> give_me_your_favorite_outfile_name.txt
echo " done"
done
for i in `find . -iname '*phtml' `
do
echo -n "Processing $i ..."
# echo " +++++++ from $i ++++++++" >> give_me_your_favorite_outfile_name.txt
cat $i | sed -n -e '/->translate(*/p' | sed -e 's/\(.*->translate(.\)\([a-z A-Z \d092\d039\d034]*\)\(.*\)/\2/g' | sed -e 's/\(.*\)\(\d039\)/\1/g' | sed -e 's/\(.*\)\(\d034\)/\1/g' >> give_me_your_favorite_outfile_name.txt
echo " done"
done
Unfortunately, it does not cover all the above cases, especially the Quotes within Quotes cases. As I am not a shell expert at all and need that script for a verification process, I would be very happy to get help from you guys.
Important: It has to be written in Shell. A PHP Version exists.