Hello,

I downloaded a php script for translating webpages. It looks like this.

<?php

// edit this line for your domain ex: http://www.domain.com
$myurl = "http://www.domain.com";



// get the url
$path = $_SERVER['REQUEST_URI'];
// split it in pieces
$urlpath = split("/", $path);
// get the language they want
$tlang2 = $urlpath[3];

$gboy = $_POST['gboy'];

// make sure it came from our form if it didn't kill it
if(!$gboy == "") {
        echo "NO LEECHING!!!";
        exit();
                }


// now we have the language they want make it something we can use
if ($tlang2 == "English") { $tlang = "en"; }
if ($tlang2 == "German") { $tlang = "de"; }
if ($tlang2 == "Spanish") { $tlang = "es"; }
if ($tlang2 == "French") { $tlang = "fr"; }
if ($tlang2 == "Italian") { $tlang = "it"; }
if ($tlang2 == "Portuguese") { $tlang = "pt"; }
if ($tlang2 == "Japanese") { $tlang = "ja"; }
if ($tlang2 == "Korean") { $tlang = "ko"; }
if ($tlang2 == "Chinese-Simplified") { $tlang = "zh-CN"; }

  // Get the url that they want to translate
     $site = $_GET['u'];
  // they are playing with the urls here
     if (empty($site)) {
        $site = "$myurl";
                                                         }

    $language = $tlang;

    if (empty($language)) {

        $language = $tlang;
                    if ($language == "") {
                       $language = "en";
                                        }
                                         }

 $script_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];

 // this is the url we need to see stay on our domain
 $translated = "http://216.239.39.104/translate_c?hl=en&ie=UTF-8&oe=UTF-8&langpair=en|$tlang&u=$site";

 // fix the links to stay on our domain
 $data = fopen("$translated", "rb");
 $data2 = '';
 while (!feof($data)) {
   $data2 .= fread($data, 8192); }

   // change what we need to
   $new_code .= str_replace("http://216.239.39.104/translate_c?hl=en", "$script_url/?$language", $data2);

   // get rid of what we don't need
   $new_code2 .= str_replace("hl=en", "", $new_code);
   $new_code3 .= str_replace("&ie=UTF-8", "", $new_code2);
   $new_code4 .= str_replace("&oe=UTF-8", "", $new_code3);
   $new_code5 .= str_replace("fr&langpair=en%7Cfr&", "", $new_code4);  // done
   $new_code6 .= str_replace("es&langpair=en%7Ces&", "", $new_code5);  // done

   $new_code7 .= str_replace("de&langpair=en%7Cde&", "", $new_code6); // done
   $new_code8 .= str_replace("en&langpair=en%7Cen&", "", $new_code7); // done
   $new_code9 .= str_replace("it&langpair=en%7Cit&", "", $new_code8); // done
   $new_code10 .= str_replace("pt&langpair=en%7Cpt&", "", $new_code9); // done
   $new_code11 .= str_replace("ja&amp;ie=UTF-8&amp;oe=UTF-8&amp;langpair=en%7Cja&amp;", "", $new_code10);
   $new_code12 .= str_replace("ko&amp;ie=UTF-8&amp;oe=UTF-8&amp;langpair=en%7Cko&amp;", "", $new_code11);
   $new_code13 .= str_replace("zh-CN&amp;ie=UTF-8&amp;oe=UTF-8&amp;langpair=en%7Czh-CN&amp;", "", $new_code12);
   fclose($data);

   echo "<center><a href=\"$myurl\"><FONT SIZE=\"2\">Click Here For English Version</FONT></a></center>";   
// display our translated page
echo $new_code13;



?>

The thing is this php is in a extensionless file called language. Along with it came a .htaccess file and a readme file.

The readme goes like this:

Requirements: php enabled server

Edit the value $myurl to match your http://www.domain.com address in the form offered below and the file named "language"
make any subdirectory you want the files in. place the files .htaccess and language in that directory.
Do not add theses files to your root directory.
This script is complient with standards of search engines that follow drop down menus.

Your form to add to the site - you can add ther form on any page you want.


<?
// edit this line for your domain ex: http://www.domain.com
$myurl = "http://www.domain.com";
// No need to edit anything else
echo "<font size=\"1\"><B>Select Your language</B></font><BR>
<form name=\"mnfrm\">
<select name=\"tlang\" onChange=location.href=mnfrm.tlang.options[selectedIndex].value>
<option value=\"#\" selected>Choose</option>
<option value=\"$myurl/translate/language/German\">German</option>
<option value=\"$myurl/translate/language/Spanish\">Spanish</option>
<option value=\"$myurl/translate/language/French\">French</option>
<option value=\"$myurl/translate/language/Italian\">Italian</option>
<option value=\"$myurl/translate/language/Portuguese\">Portuguese</option>
<option value=\"$myurl/translate/language/Japanese\">Japanese </option>
<option value=\"$myurl/translate/language/Korean\">Korean</option>
<option value=\"$myurl/translate/language/Chinese-Simplified\">Chinese&nbsp;(Simplified) </option>
</select><BR>
</form>";
?>

I've done as instructed but using the dropdown list from a web page just calls up a page that does not exsist.

I dont understand how the form is linking to the language/php file as there seems to be no reference to it.

The .htaccess file looks like this

<Files language>
ForceType application/x-httpd-php
</Files>

Any help would be much apreciated.

Matt

    I am not sure
    but I suggest your try this:

    The first code you have in your post,
    rename that php script to language.php

    The other FORM select, you can call for example lang_select.php

    In this lang_select.php
    change this line

    // change this line  <form name=\"mnfrm\">
    // to
    echo "
    
    <form name=\"mnfrm\" action=\"language.php\">
    
    ";

    Both these php pages should of course be in SAME FOLDER.

    When somebody now makes a SELECT
    in the form, script will continue to 'language.php'
    as told in
    action="language.php"
    And as now this page exists, page will also be found.

    There might be several other details to change and fix
    before eveything works
    but lets start with this.

    ( I do not know if you need to put in a SUBMIT button
    in your form ???
    Maybe is not needed when using SELECT drop down menu .. )

    Regards
    /halojoy

      Watch out how you use this, though. It's calling Google to actually do the translation work, and then taking all the credit for it. I'm not sure that Google would approve.

      Having said that, the instructions look a little off.

      The form will call something like
      http://www.yourdomain.com/translate/language/French

      I would imagine that your language file needs to be saved as language in a directory called "translate". You would also need to do some apache tweaking so that it would know to actually call http://www.yourdomain.com/translate/language

      It also looks like the form doesn't quite match the php code. For example, the php code wants a form variable called gboy set which the form doesn't actually set, also a variable called u.

      I think that a few quick edits could make this simpler to set up. I don't have access to a PHP environment here to actually get stuck into the coding, but it could be cleaned up to make it more straightforward.

      PM me if you're interested.

        hello again

        [right]
        I like to add:

        If you are running this on a Windows machine:
        then problem is that ".htaccess" wont work
        in that case not much use of this script
        that would need to be totally re-written

        But if you run on Linux, your script might work with only smaller changes
        [/right]
        ๐Ÿ™‚

        halojoy

          Well who ever posted this script didnt do a very good job then ey!

          Im running on a linux based server and have used htaccess files before. So halojoy you still sticking to changing the extension to php? The way I see it is that doing that would remove the need for the .htaccess file.

          I havnt had time to fiddle with it yet but will get back to you guys. Would be nice to get this working. I know it leaches off google and that they will probaby clamp it down eventually but I would still like to see if it can work.

          M.

            damanic wrote:

            Well who ever posted this script didnt do a very good job then ey!

            Im running on a linux based server and have used htaccess files before. So halojoy you still sticking to changing the extension to php? The way I see it is that doing that would remove the need for the .htaccess file.

            I havnt had time to fiddle with it yet but will get back to you guys. Would be nice to get this working. I know it leaches off google and that they will probaby clamp it down eventually but I would still like to see if it can work.

            M.

            Yeah, you are right
            .htaccess makes any file, even those without extension, be processed by php.exe (php.bin)
            Now that you are on Linux with Apache server,
            and if .htaccess is set to 'Override ALL' in httpd.conf
            you need not make changes I suggested.
            But maybe you have not Allow Overide 'All', but only Override some Options ...

            Anyway, what that script is supposed to do,
            should be possible to re-write in a simple and more usable way.
            That would work not only with apache and LInux, but with Windows and other webservers.

            Right now I am testing a fastcgi http free server:
            it should outperform apache 1.3 as well as apache 2

            Unzipped sizes:

            lighttpd-1.4.0 is: 3 MB

            Apache 2.0.54 is: 60 MB .........

            my lighttpd setup uses port #8888
            (apache 2.0.54 is regular port #80)

            Benchmark comparision: lighttpd1.4, apache1.3, apache2.0
            at
            http://213.100.118.115:8888/index.html

            My regular apache
            http://213.100.118.115:80/wiki/index.php

            ๐Ÿ†’

              Ok having looked at it I realised that renaming the language file to .php probably isnt going to work. For the simple reason that if it did then the guy who came up with this script would not of done this whole .htaccess thing.

              I did however try what you suggested halojoy but it didnt work.

              Becasue of the method used Im baffled as to how to get this to work. Some one must be able to take this code and use it/ Understand what this coder was up to. I wish I could but it makes absolutly no sence to me at all!

              M.

                is there a link
                to where you got this script from?
                - any DEMO somewhere?

                • Is the script namned to something?
                  We can go search with google
                  and find some stuff about it.

                Maybe someone else have already used it,
                and solved the mystery of setting it up
                so working as intended by the developer..

                ๐Ÿ˜•

                  any one managed to get it working then?

                  • failing that does anyone know a script that will translate pages on the fly without adds, banners etc.
                    hotscripts.com wrote:

                    Description:
                    Uses googles translator service.
                    Helps with site promotion in multiple languages.
                    You are able to place a dropdown form on any pages(s) and have your site not only read in multiple languages
                    but also crawled by search engines in those languages.
                    Your code stays intact and all translated pages stay within your domain.
                    Contains 3 files.
                    One of these being a very easy to follow README file.

                    I have downloaded myself now
                    and will have a close look at it

                    Maybe I can get it work!

                    Not many things are imposible,
                    when we REALLY set our mind to it .....

                    Determination, Please!!

                    :p

                      this

                      is what I get when click on

                      Itaiano:

                      ITALIANO wrote:

                      Click Here For English Version
                      Requisiti: il php ha permesso l'assistente

                      Pubblichi il valore della variabile "$$myurl" per abbinare il vostro indirizzo del website
                      1. nella forma ha offerto sotto
                      2. nella lima chiamata "language"

                      Faccia "/translate/" del subdirectory in vostro website.
                      In quale disponete le files:
                      - htaccess
                      - language

                      Non aggiunga le lime di tesi al vostro indice di radice.
                      Questo scritto รจ complient con i campioni dei motori di ricerca
                      quello segue la goccia si scola i menu.

                      La vostra forma da aggiungere a qualsiasi pagina che desiderate,
                      nel vostro website,
                      segue qui sotto.

                      Selezioni la vostra lingua:
                      <dropdown form here>

                      Yes,
                      it is possible to get it working
                      and it uses google translation service
                      to give a translated copy of any page at your website

                      Dropdown menu <FORM> has to be paste into the page you want to translate.

                      The readme is not very good
                      and there are a couple of small but important issues
                      that has to be changed, to get it work!

                      Nice script you found, If only was not these small 'bugs' and bad documentation.

                      If you want I can re-write it all and send you in ZIP.
                      A better 'halojoy-version' that does function just same
                      but with easier fix and setup.
                      I can not promise it tomorrow, but within 1-2 months.

                      When I get time, I might publish a script like this for anyone to use!
                      With good installing instructions.

                      Thanks my friend,
                      for pointing to this hotscript.

                      And yes, I was right
                      Determination --- some hard thinking and tracking php errors
                      and we can get most anything work

                      ๐Ÿ†’

                        Ooo so you got it working halo? what do I have to do?

                        Spill the beans ๐Ÿ™‚

                          damanic wrote:

                          Ooo so you got it working halo?
                          what do I have to do?
                          Spill the beans
                          ๐Ÿ™‚

                          Well,
                          i do not remember exactly everything I changed
                          but was several variables
                          and of course

                          You should start with this install/setup:
                          ( See info in the italian ReadMe text above!!!!!!!! ๐Ÿ˜ƒ ๐Ÿ˜ƒ )

                          Wherever on your website you have that dropdown form
                          script will be looking for this php script, to do the translation:
                          $myurl + /translate/language

                          So start by
                          creating folder '/translate/'
                          and put 2 files
                          - .htaccess
                          - language
                          in that folder

                          Next change
                          $myurl = your-domain-root
                          for example:

                          $myurl = http://phpbuilder.com
                          // without trailing slash!

                          This $myurl change has to made
                          1. in whatever page you have that dropdown language select for translate
                          2. in file 'language' ( is in folder $myurl . "/translate/" )

                          when you have done this
                          I might be able to recall the rest of changes I made

                          Tell me your results in next reply post here
                          and
                          we go on from there

                          okay
                          halojoy

                          ๐Ÿ†’

                            Ok, I done as you said but thats exsactly what I done first time round.

                            I specified myurl in both language and on the form for the page I want to translate. language and htaccess put in the folder 'translate'.

                            Same as before I get a 404 page doesnt exsist with the url:

                            http://www.mydomain.com/translate/language/French

                              I have changed it everywhere... that was just an example.

                              The actual url it went to was

                              Here

                                im staying right out of this, but, when i tried to access http://www.chinalifeweb.com/translate/language my browser tried to download a file of the extension phtml.

                                i would check this .htaccess file you guys have been talking about. seems like you may need to make some adjustments in there.

                                  Hi,

                                  I got a bit sick and tired of this thread. So I took the code and had a look at it.

                                  I have one problem, opening the translated page. I am assuming it is a problem with wrappers which are not correct on my local machine. Give it a try.

                                  file: translateme.php

                                  
                                  <?
                                  // set this to the page to be translated, and place in the page from which you want to link, usually the page to be translated
                                  $mypage = "http://www.bio-vision.nl/index.php";
                                  
                                  // No need to edit anything else
                                  echo "<font size=\"1\"><B>Select Your language</B></font><BR>
                                  <form name=\"mnfrm\">
                                  // if the language.php page is in a differewnt folder, add the relative path i the optionlist
                                  
                                  <select name=\"tlang\" onChange=location.href=mnfrm.tlang.options[selectedIndex].value>
                                  <option value=\"#\" selected>Choose</option>
                                  <option value=\"language.php?tlang=es&amp;u=$mypage\">Spanish</option>
                                  <option value=\"language.php?tlang=fr&amp;u=$mypage\">French</option>
                                  <option value=\"language.php?tlang=it&amp;u=$mypage\">Italian</option>
                                  <option value=\"language.php?tguag=pt&amp;u=$mypage\">Portuguese</option>
                                  </select><BR>
                                  </form>";
                                  ?>
                                  

                                  and the language page:

                                  <?php
                                  
                                  $tlang = $_GET[tlang];
                                  
                                    // Get the url that they want to translate
                                       $site = $_GET['u'];
                                    // they are playing with the urls here
                                       if (empty($site)) {
                                          $site = "$myurl";
                                                                                           }
                                  
                                      $language = $tlang;
                                  
                                      if (empty($language)) {
                                  
                                          $language = $tlang;
                                                      if ($language == "") {
                                                         $language = "en";
                                                                          }
                                                                           }
                                  
                                   $script_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
                                  
                                   // this is the url we need to see stay on our domain
                                   $translated = "http://216.239.39.104/translate_c?hl=en&ie=UTF-8&oe=UTF-8&langpair=en|$tlang&u=$site";
                                  
                                   // fix the links to stay on our domain
                                   $data = fopen("$translated", "r");
                                   $data2 = '';
                                   while (!feof($data)) {
                                     $data2 .= fread($data, 8192); }
                                  
                                     // change what we need to
                                     $new_code .= str_replace("http://216.239.39.104/translate_c?hl=en", "$script_url/?$language", $data2);
                                  
                                     // get rid of what we don't need
                                     $new_code2 .= str_replace("hl=en", "", $new_code);
                                     $new_code3 .= str_replace("&ie=UTF-8", "", $new_code2);
                                     $new_code4 .= str_replace("&oe=UTF-8", "", $new_code3);
                                     $new_code5 .= str_replace("fr&langpair=en%7Cfr&", "", $new_code4);  // done
                                     $new_code6 .= str_replace("es&langpair=en%7Ces&", "", $new_code5);  // done
                                  
                                     $new_code7 .= str_replace("de&langpair=en%7Cde&", "", $new_code6); // done
                                     $new_code8 .= str_replace("en&langpair=en%7Cen&", "", $new_code7); // done
                                     $new_code9 .= str_replace("it&langpair=en%7Cit&", "", $new_code8); // done
                                     $new_code10 .= str_replace("pt&langpair=en%7Cpt&", "", $new_code9); // done
                                     $new_code11 .= str_replace("ja&amp;ie=UTF-8&amp;oe=UTF-8&amp;langpair=en%7Cja&amp;", "", $new_code10);
                                     $new_code12 .= str_replace("ko&amp;ie=UTF-8&amp;oe=UTF-8&amp;langpair=en%7Cko&amp;", "", $new_code11);
                                     $new_code13 .= str_replace("zh-CN&amp;ie=UTF-8&amp;oe=UTF-8&amp;langpair=en%7Czh-CN&amp;", "", $new_code12);
                                     fclose($data);
                                  
                                     echo "<center><a href=\"$myurl\"><FONT SIZE=\"2\">Click Here For English Version</FONT></a></center>";   
                                  // display our translated page
                                  echo $new_code13;
                                  
                                  ?>
                                  

                                    hi again

                                    to make this form more universal
                                    to be simply copied into any page
                                    we should use PHP_SELF to get page to be translated

                                    leatherbacks New version, will give some work
                                    depending on where we paste this dropdown menu into any page

                                    Here is halojoy nice suggestion instead.
                                    Using the Original script, for less rewriting.
                                    remember I have Original script up and working already!

                                    <?
                                    
                                    // without trailing slash!
                                    $phpself = $_SERVER[ 'PHP_SELF' ]; // get page this form is on
                                    $myurl = "http://root-of-your-website"; 
                                    // 
                                    // No need to edit anything else 
                                    echo "<font size=\"1\"><B>Select Your language</B></font><BR> 
                                    <form name=\"mnfrm\"> 
                                    <input type='hidden' name='trpage' value='" . $phpself . "'>
                                    <select name=\"tlang\" onChange=location.href=mnfrm.tlang.options[selectedIndex].value> 
                                    <option value=\"#\" selected>Choose</option> 
                                    <option value=\"$myurl/translate/language/German\">German</option> 
                                    <option value=\"$myurl/translate/language/Spanish\">Spanish</option> 
                                    <option value=\"$myurl/translate/language/French\">French</option> 
                                    <option value=\"$myurl/translate/language/Italian\">Italian</option> 
                                    <option value=\"$myurl/translate/language/Portuguese\">Portuguese</option> 
                                    <option value=\"$myurl/translate/language/Japanese\">Japanese </option> 
                                    <option value=\"$myurl/translate/language/Korean\">Korean</option> 
                                    <option value=\"$myurl/translate/language/Chinese-Simplified\">Chinese&nbsp;(Simplified) </option> 
                                    </select><BR> 
                                    </form>"; 
                                    ?>

                                    now you can alter the other script:
                                    language

                                    to get and use

                                    this hidden variable
                                    $trpage
                                    which carry the URL
                                    of page to be translated by Google

                                    trpage = translated page
                                    [right]so now it can work wherever we paste this form into a page or script
                                    because halojoy has used PHP_SELF
                                    to store page that does the request of translation[/right]

                                    /halojoy ๐Ÿ™‚ ๐Ÿ™‚ ๐Ÿ™‚