PHP - Translate
If I hypoteticly have a website that only contains one word.. eh.. "Hello World".
So.. my question is would I be able to translate this into other languages using.. the Google translate API for an example? So basicly I want to do is: Detect what country you're from (probably trought IP), translate the words "Hello World" to whatever language you're in. Is there any translate API's that does this? I don't really care about if it's going to be right spelled etc. I only have single words I want to translate! It would be really awesome! If not.. oh.. ! Similar Tutorialshi, i looking for a best way to translate a backoffice content. options: A- i can use a separate file each for a lang with all vars. B- use a table with all data both of this solutions have a big time to implement and in all areas that i creat i need add the vars. there is some best solution for this? something that can translate all content like google translator? thanks for your help Please translate: $req_user = trim($_GET['user']); if(!$req_user || strlen($req_user) == 0 || !eregi("^([0-9a-z])+$", $req_user) || !$database->usernameTaken($req_user)){ die("Username not registered"); $req_user_info = $database->getUserInfo($req_user); Thanks Ok I am a student and my instructor keeps giving us projects dealing with PHP coding even though only half our class has had a PHP server side scripting class. The project he just gave us I thought would be simple, but I'm still struggling to find online the proper scripting to get my php file to do what I need it to do. Requirements : Create a simple html page that contains a text area with a submit buton - DONE The submit button will call a php page and display the text typed in the text area - DONE Allow users to enter XML script into the text area and when submit button is clicked the php page will display the XML without the XML tags, Example - Text Area Entry Would Look Like - Code: [Select] <fname>James</fname><lname>Mays</lname> Output Would Look Like - James Mays This is the part I'm struggling with, I don't know how to tell the php to not display the XML tags - NOT DONE If this helps here is what code I do have, HTML Page Code: [Select] <!DOCTYPE HTML> <html> <head> </head> <body> <form action="test.php" method="post"> <p>Text Area:</p> <textarea name="xmltags" rows="10" cols="40"></textarea></p> <p><input type="submit" value="Submit"></p> </form> </div> </div> </body> </html>PHP Code Code: [Select] <html> <body> Text Output: <?php echo $_POST["xmltags"]; ?>!<br /> </body> </html> Thank You for any and all help translate my code please; javascript to php. very very very very thanks. <form> <input type="checkbox" name="myfilter" value="+abst">Amytag1 <input type="checkbox" name="myfilter" value="+mini">Amytag8 <input type="checkbox" name="myfilter" value="+popa">Amytag9 <input type="checkbox" name="myfilter" value="+impr">Amytag13 <input type="checkbox" name="myfilter" value="+green">Amytag15 <input type="checkbox" name="myfilter" value="+gh5">Amytag18 <input type="checkbox" name="myfilter" value="+gh4">Amytag19 <input type="checkbox" name="myfilter" value="+gh3">Amytag34 <input id="search1" placeholder="Word Search..." value=""> <input id="year1" placeholder="Year" value=""> <input id="month1" placeholder="Month" value=""> <input id="day1" placeholder="Day" value=""> <input id="mymenu" value=""> </form> <button onclick="myFunction()" class="Sbutton">search it</button> <script> function myFunction() { var myfilter = document.forms[0]; var txt = ""; var i; for (i = 0; i < myfilter.length; i++) { if (myfilter[i].checked) { txt = txt + myfilter[i].value; } var year = "&year=" + document.getElementById("year1").value; var month = "&month=" + document.getElementById("month1").value; var day = "&day=" + document.getElementById("day1").value; var search = "&s=" + document.getElementById("search1").value; var tag = "/?tag=" + document.getElementById("mymenu").value; } var zzz = "http://test.com/category/art" + txt + tag + year + month + day + search; window.location.assign(zzz) } </script>
and please, not use this way: header("Location: {$target}"); exit; Because it doesn't work on my site (for some reason). p.s: I have a lot of checkbox. Edited May 4, 2020 by ldonopI've signed up for Google's translating service and I'm able to get results, however, it's wrapped around some information. Here's an example: Code: [Select] //Content to translate - Spanish for 'Hello World' $content = urlencode("Hola Mundo"); $translate = file_get_contents("https://www.googleapis.com/language/translate/v2?key=MyKey&q=$content&source=es&target=en"); echo $translate; The code returns { "data": { "translations": [ { "translatedText": "Hello World" } ] } } All I want is the result Hello World I tried using str_replace but it does not work through file_get_contents. The Google Translate does not provide any information on how to do this. Does anyone have any ideas? i have this in a form Code: [Select] <textarea id='textarea' name='tweet' maxlength=140 > <?php if(isset($_SESSION['description'])) { echo $_SESSION['description'];} ?> </textarea> the session variable is just their input and i use that to repopulate the form if the validation script catches an error with their input. The problem is when the user enters carriage returns and then if theirs an error.... this... "blah blah blah" turns into this... "blah blah\r\n\r\nblah" how do i remove that junk? I have a comment form in which the users type thier comment in english.Those pcomments should appear in the native laguage other than english in my website.Is there any php code to do this.i dont have any idea of creating a site other than english. I'm trying to translate a website using PHP gettext. However, it doesn't work. I added Italian translations, but I only see one character instead of the translation. The single character is not the first character in the string. I add this to every page: Code: [Select] putenv('LC_ALL=it_IT'); setlocale(LC_ALL, 'it_IT'); bindtextdomain('messages', './locale'); textdomain('messages'); I define every string using: $string = _('string'); In my locale folder I have the following folder structu it_IT > LC_MESSAGES > messages.mo/messages.po. I've tried a lot of things, but I can't get it to work. What am I doing wrong? Can anyone help me? This script is supposed to run in the command line. Like the title says, I need to: Import some columns (input the names with an argument) from a .CSV file Split the column into blocks of 500 lines Translate this pieces Put them back into the original file I already have some code but it is unfinished and not working: <?php //name of the .CSV file $filename = $argv[1]; //name of the column to be translated $header_name = $argv[2]; //open file $file_handle = fopen($filename, "r"); $i=0; $j=0; $counter = 0; $translated = ''; $string = ''; while (!feof($file_handle) ) { $counter++; $line_of_text = fgetcsv($file_handle, 1024); //find the column id that contains the header name. // headers are always on the the first line if ( $counter == 1 ){ while ($line_of_text[$i] != $header_name) $i++; $header_id = $i; } //create the blocks $string .= $line_of_text[$i]; if ($counter % 500 == 0) { $gt = new GoogleTranslateWrapper(); $translated .= $gt->translate($string, "en"); } } //Write the translate column in the same .CSV file fclose($file_handle); ?> Any help in rewriting this to work? |