Page 1 of 1

Automatically redirect to Google Translator when certain dom

Posted: Tue Aug 11, 2009 9:22 pm
by Mr Tech
I have set-up Google Translation on a clients website. He currently owns the .net for his domain and also wants to buy other country TLDs such as .de, .cn etc etc He wants it so that when you load the website using another countries TLD, it will redirect and translate the page.

I've got a PHP function that works except it redirects over and over because even though Google loads the website in a framed page, it doesn't give any $_GET or $_POST variables so I can determine whether it has already been redirected or not. Am I making sense? My code below?

Code: Select all

function curPageURL() {
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on")
        $pageURL .= "s";
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80")
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    else
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    return $pageURL;
}
if (preg_match('|\.de|', $_SERVER["SERVER_NAME"], $match)) {
    header('location: http://translate.google.com/translate?u=' . urlencode(curPageURL()) . '&hl=en&langpair=auto|de&tbb=1&ie=UTF-8');
}
Or is there a PHP function that allows you to detect the content language so I can check to see if it is no longer english and has been translated? Any input would be fantastic!

I hope this message makes sense...

Re: Automatically redirect to Google Translator when certain dom

Posted: Wed Aug 12, 2009 3:47 am
by dejvos
Hello!

You can parse user language from $_SERVER['HTTP_USER_AGENT'].

I don't know your expreriences with Google translate, but I'm Czech and it works absolutly terrible ... it doesn't keep meaning of the phrases! I'm not sure if google translate is a right way.

Re: Automatically redirect to Google Translator when certain dom

Posted: Wed Aug 12, 2009 4:07 am
by turbolemon
For a more long-term solution, you could consider coding for multiple languages. For example, Zend Framework provides a method to facilitate multiple language support using Zend_Translate. This allows you to provide alternative content, supporting translation sources in many different formats. This way you could get translations from human sources which accurately reflected the content (a problem with automatic translation!).

http://framework.zend.com/manual/en/zend.translate.html

Re: Automatically redirect to Google Translator when certain dom

Posted: Wed Aug 12, 2009 6:09 pm
by Mr Tech
Thanks for the replies. So does Zend_Translate do the translation for you or is it something you still have to do manually?

Re: Automatically redirect to Google Translator when certain dom

Posted: Thu Aug 13, 2009 4:02 am
by turbolemon
It's manual. You give a unique 'name' for each translated text, and it reads from the relevant language file.

Re: Automatically redirect to Google Translator when certain dom

Posted: Thu Aug 13, 2009 8:27 am
by Eric!
I can tell you that translations programs for English work well for Spanish, because of the similarity between Spanish and English grammer and verb usage, however it is not very good for German.

I think that usually this type of language selection is done based on geo-referenced IP lookups, not based on domain names. I don't think you need to bother buying all the .co, .dr, .cz domains for each country. You can just make your site mutil-lingual either by picking a display language based on IP of the host $_SERVER['REMOTE_ADDR'] or allowing the user to choose.

Since I travel a lot, I personally hate geo-referenced IP's because I'm always forced to search for the "English" button to switch sites back to english. However I'm sure it's great for people who live in those countries and don't speak English as a first language.

Try this lookup for IP info:
http://www.hostip.info/