RegEx Module HOWTO: Geek notes followI've used the new Regular Expression Pipes Module to rewrite the link text and automatically rebuild the link so that it passes through Google's translate service. Here's how you do this.
- Your source is a foreign language RSS feed. I fetch feeds from L'Equipe and LeMonde using the FETCH module.
- I pipe my sources to the BABELFISH module and specify "French to English." This translates the Titles and Descriptions in the feed from French to English. This is great for reading inside the feed reader, but these feeds provide summaries only. For the entire article, you must click on the link to the French-language article.
- I create a REGEX module and run a pipe from BABELFISH to REGEX.
- Create a rule within module REGEX that looks like this:
In LINK replace ^ with http://translate.google.com/translate?langpair=fr|en&hl=en&ie=UTF8&u=
"LINK" tells the REGEX module to replace something in the link text. The carat symbol (^) is the regular expression symbolizinng "beginning of the line." This means that the regex module will point to the beginning of the link line -- which will be the start of the WWW URL pointing to the article at L'Equipe's website. The rest of it is the WWW URL for Google's translate service. The original URL -- the WWW link pointing to L'Equipe -- is moved over so that it comes after Google's translate URL, with the "u=" meaning this is the URL for Google to translate.
- Run a pipe from the REGEX module to the PIPE OUTPUT, Save and Test.
- Some RSS feeds (including L'Equipe) create redirections, which the translator has a hard time dealing with sometimes. You may need some additional regex magic to fix the redirection problem.
If this pipe is useful, if these directions are helpful, or if you've created an RSS feed of your own using Pipes and the RegEx module, please leave a comment here.