ForeverDev

Language Translator

Sep 13th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. --[[
  2.     HOW THE LANGUAGE WORKS :
  3.         This is inspired by a stupid little 'secret language' my 2nd grade teacher taught me.
  4.        
  5.         Basically, take a word and iterate through the letters.  If the letter is a vowel,
  6.             then leave it be.  If the letter is not a vowel, add "op" to the end of it.
  7.             For example, "Hi" would result in "HOPi", and "face" would result in "fopacope"
  8.            
  9.         TODO: add an ignore list with characters such as ".", "?", "!", etc.
  10. ]]
  11.  
  12. local vowels = {
  13.     a = true, e = true, i = true, o = true, u = true
  14. }
  15.  
  16. local translate = {
  17.    
  18.     toEnglish = function(words)
  19.         local product = {}
  20.         for letter = 1, words:len() do
  21.             local let = words:sub(letter, letter)
  22.             if words:sub(letter + 1, letter + 2):lower() == "op" then
  23.                 table.insert(product, let)
  24.             elseif vowels[let:lower()] and words:sub(letter + 1, letter + 1):lower() ~= "p" then
  25.                 table.insert(product, let)
  26.             end
  27.         end
  28.         return table.concat(product)
  29.     end,
  30.    
  31.     toLanguage = function(words)
  32.         local product = {}
  33.         for letter = 1, words:len() do
  34.             local let = words:sub(letter, letter)
  35.             table.insert(product, let == " " and " " or vowels[let:lower()] and let or let == let:lower() and let .. "op" or let .. "OP")
  36.         end
  37.         return table.concat(product)
  38.     end
  39.    
  40. }
  41.  
  42. local to = translate.toLanguage("My name is David")
  43. print(to) --OUTPUT: MOPyop nopamope isop DOPavopidop
Advertisement
Add Comment
Please, Sign In to add comment