2

I have 60 expressions and single words that i need to translate into English.

How can I design a simple (pure) JavaScript function to translate those 60 items? I need just an idea (design) not full code.

I wrote the 60 items to translate in English too. I just do not know how to link an item from one language to an other.

P.S. I do not want jQuery, Google Translate API and so on ... Just pure JavaScript.

avazwij
  • 91
  • 1
  • 8

1 Answers1

4

Put all your expressions in a map and use it to translate

var languageMap = {
  "bonjour" : "Hello",
  "au revoir" : "Goodbye"
};

var word = "bonjour";
var inEnglish = languageMap[word];
console.log(word,"in english is",inEnglish)

Watch out, lookup here is case sensitive though. If you can't guarantee the casing of your input words you'll need something smarter.

Jamiec
  • 133,658
  • 13
  • 134
  • 193