SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    0 Post(s)
    0 Thread(s)

    Automatically redirect to Google Translator when certain domain TLD used

    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?

    PHP Code:
    function curPageURL() {
    $pageURL 'http';
        if (
    $_SERVER["HTTPS"] == "on"
    $pageURL .= "s";
    $pageURL .= "://";
        if (
    $_SERVER["SERVER_PORT"] != "80")
    if (
    preg_match('|\.de|'$_SERVER["SERVER_NAME"], $match)) {
    header('location:' 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...

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    West Springfield, Massachusetts
    198 Post(s)
    3 Thread(s)
    AFAIK most if not all browsers should send info in the HTTP headers. i.e.
    Accept-Language: en-us,en;q=0.5

    I'm foggy on the specs, but I think the languages are in order of priorty and weighted (the q).

    If you could intercept that header info it should help.

    Rather than a redirect to Google Translator, have you considered something like gettext?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts