Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Translator keep dropping all punctuation

    I'm currently working on a translater that works in javascript that takes normal English and changes it into Pirate lingo, however I can't get to so that punctuation will appear in the translation. Any help that you could offer would be great.

    My current code is:
    Code:
    <!--
    	function translateText(text)
    	{
    		text = text.toLowerCase();
    
    		var textArray = text.split(" ");
    		
    		var output = "";
    		var arrayLength = textArray.length;
    		var wordLength;
    
    		for (var i = 0; i < arrayLength; i++)
    		{
    			if (textArray[i].indexOf("rear") != -1)
    			output += "aft";
    			else if (textArray[i].indexOf("after") != -1)
    			output += "aft";
    			else if (textArray[i].indexOf("hello") != -1)
    			output += "ahoy";
    			else if (textArray[i].indexOf("oh no") != -1)
    			output += "arrg";
    			else if (textArray[i].indexOf("stop") != -1)
    			output += "avast";
    			else if (textArray[i].indexOf("hey") != -1)
    			output += "avast";
    			else if (textArray[i].indexOf("who goes there") != -1)
    			output += "avast";
    			else if (textArray[i].indexOf("stop that") != -1)
    			output += "belay";
    			else if (textArray[i].indexOf("nonsense") != -1)
    			output += "bilge";
    			else if (textArray[i].indexOf("lies") != -1)
    			output += "bilge";
    			else if (textArray[i].indexOf("wow") != -1)
    			output += "blimey";
    			else if (textArray[i].indexOf("holy crap") != -1)
    			output += "blimey";
    			else if (textArray[i].indexOf("boatswain") != -1)
    			output += "bosun";
    			else if (textArray[i].indexOf("pirate") != -1)
    			output += "buccaneer";
    			else if (textArray[i].indexOf("friend") != -1)
    			output += "bucko";
    			else if (textArray[i].indexOf("my") != -1)
    			output += "me";
    			else if (textArray[i].indexOf("whip") != -1)
    			output += "cat o'nine tails";
    			else if (textArray[i].indexOf("song") != -1)
    			output += "chantey";
    			else if (textArray[i].indexOf("victim") != -1)
    			output += "chase";
    			else if (textArray[i].indexOf("sword") != -1)
    			output += "cutlass";
    			else if (textArray[i].indexOf("sea") != -1)
    			output += "Davy Jones' locker";
    			else if (textArray[i].indexOf("ocean") != -1)
    			output += "Davy Jones' locker";
    			else if (textArray[i].indexOf("eyes") != -1)
    			output += "deadlights";
    			else if (textArray[i].indexOf("money") != -1)
    			output += "dubloons";
    			else if (textArray[i].indexOf("move") != -1)
    			output += "gangway";
    			else if (textArray[i].indexOf("drink") != -1)
    			output += "grog";
    			else if (textArray[i].indexOf("you") != -1)
    			output += "ye";
    			else if (textArray[i].indexOf("cannon") != -1)
    			output += "gun";
    			else if (textArray[i].indexOf("forword") != -1)
    			output += "fore";
    			else if (textArray[i].indexOf("front") != -1)
    			output += "fore";
    			else if (textArray[i].indexOf("sailors") != -1)
    			output += "hands";
    			else if (textArray[i].indexOf("helpers") != -1)
    			output += "hands";
    			else if (textArray[i].indexOf("quickly") != -1)
    			output += "handsomely";
    			else if (textArray[i].indexOf("hangman") != -1)
    			output += "Jack Ketch";
    			else if (textArray[i].indexOf("flag") != -1)
    			output += "Jolly Rogger";
    			else if (textArray[i].indexOf("boy") != -1)
    			output += "lad";
    			else if (textArray[i].indexOf("girl") != -1)
    			output += "lass";
    			else if (textArray[i].indexOf("person") != -1)
    			output += "landlubber";
    			else if (textArray[i].indexOf("rope") != -1)
    			output += "line";
    			else if (textArray[i].indexOf("crew") != -1)
    			output += "hearties";
    			else if (textArray[i].indexOf("friends") != -1)
    			output += "hearties";
    			else if (textArray[i].indexOf("nose") != -1)
    			output += "prow";
    			else if (textArray[i].indexOf("telescope") != -1)
    			output += "spyglass";
    			else if (textArray[i].indexOf("right") != -1)
    			output += "starboard";
    			else if (textArray[i].indexOf("left") != -1)
    			output += "port side";
    			else if (textArray[i].indexOf("woman") != -1)
    			output += "wench";
    			else if (textArray[i].indexOf("women") != -1)
    			output += "wenches";
    			else if (textArray[i].indexOf("chick") != -1)
    			output += "wench";
    			else if (textArray[i].indexOf("chicks") != -1)
    			output += "wenches";
    			else if (textArray[i].indexOf("yay") != -1)
    			output += "yo-ho";
    			else if (textArray[i].indexOf("woohoo") != -1)
    			output += "yo-ho";
    			else if (textArray[i].indexOf("are") != -1)
    			output += "be";
    			
    			else output += textArray[i]
    			
    
     			 if (i != arrayLength - 1 && textArray[i+1] != "")
              		output += " ";
    		}
    
     	document.translate.translated.value = output;
    
    	}
    
    //-->
    thanks!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Learn Regular Expressions - they will make the task much easier. As is your approach is not worth fixing....
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

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