Hacking the translation plugin for nicer URLs
Published 2 years, 6 months ago in Blogs, Hacks and WordpressWhen 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:
-
// new version for mod_rewriteness
-
function get_translated_url($language='de', $url) {
-
return get_bloginfo('url') . '/translate/' . $language . '/' . $url;
-
}
-
-
/* old get_translated_url function commented out for easy restoring:
-
function get_translated_url($language='de', $url) {
-
if(!isset($url)) $url = get_bloginfo('url');
-
return get_bloginfo('url') . '/wp-content/plugins/translator.php?l=' . $language . '&u=' . $url;
-
} */
And add the following to the top of .htaccess:
-
<IfModule mod_rewrite.c>
-
RewriteEngine On
-
RewriteBase /
-
RewriteRule ^translate/([^\/]+)/(.*)$ /wp-content/plugins/translator.php?l=$1&u=$2 [L]
-
</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!
Search
Categories
- ASP (3)
- ASP Basics (3)
- Blogs (2)
- C# (1)
- Firefox (1)
- Flash (1)
- Google (6)
- Hacks (3)
- Java (1)
- PHP (12)
- Basics (8)
- Files (1)
- Image Handling (3)
- Puzzles (1)
- Ruby (1)
- Tips (10)
- Web Hosting (3)
- Web Hosting Articles (1)
- Web Hosting News (2)
- Windows (6)
- Wordpress (2)
No Responses to “Hacking the translation plugin for nicer URLs”
Please Wait
Leave a Reply
You must log in to post a comment.