jeudi 26 mars 2015

Creating a simple language translator

I'm trying to create a very simple language translator using PHP and a html form. My goal is to for the user to type whatever word he/she wants to be translated into the language chosen through the radio button. Example: They type the swedish word "Smultron" and choses the language they want through the radio buttons, and then when they hit submit the translation shows up.


My code looks like this so far:



<?php

if (isset($_POST['submit']))

$swedish = array('päron', 'apelsin', 'jordgubbe', 'ananas', 'citron', 'smultron', 'hallon', 'körsbär', 'drakfrukt', 'blåbär');
$english = array('pear', 'orange', 'strawberry', 'pineapple', 'lemon', 'wild strawberry', 'raspberry', 'cherry', 'dragon fruit', 'blueberry');
$french = array('poire', 'orange', 'fraise', 'ananas', 'citron', 'fraises sauvages', 'framboises', 'cerises', 'fruit du dragon', 'myrtille');
$spanish = array('peras', 'naranja', 'fresa', 'piña', 'limón', 'fresas silvestres', 'frambuesas', 'cerezas', 'pitaya', 'arándanos');
$russian = array('груши', 'оранжевый', 'клубника', 'ананас', 'лимон', 'земляника', 'малина', 'вишня', 'плод дракона', 'черника');
$german = array('birnen', 'orange', 'Erdbeere', 'ananas', 'Zitrone', 'Walderdbeeren', 'Himbeeren', 'Kirschen', 'Drachenfrucht', 'Blaubeeren');
?>

<html>
<body>
<form action="index.php" method="POST">
<p>Översättaren</p> <input type="text" name="text" /><br />
Engelska: <input type="radio" name="radio" value="english"/>
Spanska: <input type="radio" name="radio" value="spanish"/>
Tyska: <input type="radio" name="radio" value="german"/>
Ryska: <input type="radio" name="radio" value="russian"/>
Franska: <input type="radio" name="radio" value="french"/> <br />
<input type="submit" name ="submit"
/>
</form>
</body>
</html>


I'm stuck and I have not been able to find any answers on the subject PHP with HTML-forms and radio buttons on google/in my PHP-book. Swedish translation is not needed.


Is there anyone out there who can help me with these simple lines of codes? Much appreciated.


Aucun commentaire:

Enregistrer un commentaire