I have a client's site where we provide links to Google Translate via flag icons. I would like to provide a link back to the original language (English) from the translated result.
You can see what I've got so far in action on the top-right of any page at tesselaar.com
If you click one of the flags, the page gets translated and the flag icons are replaced with an English version. I would like this flag to link back, but as you can see it doesn't because Google Translate is rewriting the URL I give it. Does anyone know how to get around this?
Here's my code:
<?php
echo "<ul class=\"breadcrumb pull-right\">\n";
if (stripos($_SERVER['HTTP_REFERER'], "translate.google") !== false) { // page has been translated
if (empty($_SESSION['return_url'])) $_SESSION['return_url'] = "tesselaar.com";
echo "<li>View page in English:</li>\n";
echo "<li><a target=\"_top\" href=\"http://" . $_SESSION['return_url'] . "\"><img src=\"/assets/img/flags/gb.gif\" width=\"16\" height=\"11\" title=\"English\" alt=\"English\"></a></li>\n";
} else { // regular site (not translated)
$_SESSION['return_url'] = $_SERVER['REQUEST_URI'];
echo "<li>Translate this page:</li>\n";
echo "<li><a href=\"http://translate.google.com/translate?sl=en&tl=fr&u=tesselaar.com". $_SERVER['REQUEST_URI'] . "\"><img src=\"/assets/img/flags/fr.gif\" width=\"16\" height=\"11\" alt=\"French\"></a></li>\n";
echo "<li><a href=\"http://translate.google.com/translate?sl=en&tl=de&u=tesselaar.com". $_SERVER['REQUEST_URI'] . "\"><img src=\"/assets/img/flags/de.gif\" width=\"16\" height=\"11\" alt=\"German\"></a></li>\n";
echo "<li><a href=\"http://translate.google.com/translate?sl=en&tl=nl&u=tesselaar.com". $_SERVER['REQUEST_URI'] . "\"><img src=\"/assets/img/flags/nl.gif\" width=\"16\" height=\"11\" alt=\"Dutch\"></a></li>\n";
echo "<li><a href=\"http://translate.google.com/translate?sl=en&tl=es&u=tesselaar.com". $_SERVER['REQUEST_URI'] . "\"><img src=\"/assets/img/flags/es.gif\" width=\"16\" height=\"11\" alt=\"Spanish\"></a></li>\n";
echo "<li><a href=\"http://translate.google.com/translate?sl=en&tl=el&u=tesselaar.com". $_SERVER['REQUEST_URI'] . "\"><img src=\"/assets/img/flags/gr.gif\" width=\"16\" height=\"11\" alt=\"Greek\"></a></li>\n";
}
echo "</ul>\n\n";
?>
EDIT: Things I've tried, without success, since posting:
- Wrapping various things in a "notranslate" span.
- Using jQuery to try to rewrite the "link back" URL.
- Using jQuery to intercept the "link back" click and rewrite the parent frame.