Hacking the translation plugin for nicer URLs

When I first installed WordPress on this site, I went to the codex plugin list and went a bit mad over the extreme extensibility on offer, grabbing many plugins, just to try them out. A lot of them I disabled after a short while (not that they weren't good, they weren't anything I was wanting to use). Anyway, one of the plugins which is almost completely useless to me, but which I have left activated is the Simple Thoughts Automatic Translation Plugin, which provides the little translation bar with the flags which you can see on the right of this page. I left it activated simply because it is neat. :)

As I use nice mod_rewritten URLs for all other WordPress powered content on this site, I decided to try and hack the script to allow nice translation URLs:
Old: http://discomoose.org/wp-content/plugins/translator.php?l=de&u=http://discomoose.org/
New: http://discomoose.org/translate/de/http://discomoose.org/
Now, I'm not experienced with mod_rewrite at all, so this is more than likely a poorly implemented hack. But equipped with an excellent mod_rewrite beginner's guide (found via Digg) I set about trying to implement it.

What I came up with is this:
In /wp-content/plugins/translator.php, change the get_translated_url function to this:

PHP:
  1. // new version for mod_rewriteness
  2. function get_translated_url($language='de', $url) {
  3.     if(!isset($url)) $url = get_bloginfo('url');
  4.     return get_bloginfo('url') . '/translate/' . $language . '/' . $url;
  5. }
  6.  
  7. /* old get_translated_url function commented out for easy restoring:
  8. function get_translated_url($language='de', $url) {
  9.     if(!isset($url)) $url = get_bloginfo('url');
  10.     return get_bloginfo('url') . '/wp-content/plugins/translator.php?l=' . $language . '&u=' . $url;
  11. } */

And add the following to the top of .htaccess:

CODE:
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteBase /
  4. RewriteRule ^translate/([^\/]+)/(.*)$ /wp-content/plugins/translator.php?l=$1&u=$2 [L]
  5. </IfModule>

Then URLs such as /translate/<language>/<url> will work. As of yet I haven't encountered any major problems with this hack, but that's not to say there aren't any ;)

If you have a website, consider joining the Money4Banners advertising network. They will pay you £10 + £5 each month for displaying a small advert on three of your pages, regardless of traffic. American webmasters are welcome, and since £10 == $20, you make more!


No Responses to “Hacking the translation plugin for nicer URLs”  

  1. No Comments

Leave a Reply

You must log in to post a comment.


Categories