emoji-translate.js
function translate(sentence, onlyEmoji) {
  let translation = '';
  let words = sentence.split(' ');
  for (let i = 0; i < words.length; i++ ) {
    // Punctuation blows. Get all the punctuation at the start and end of the word.
    // TODO: stop copy pasting this.
    let firstSymbol = '';
    let lastSymbol = '';
    var word = words[i];

    while (SYMBOLS.indexOf(word[0]) != -1) {
      firstSymbol += word[0];
      word = word.slice(1, word.length);
    }
    while (SYMBOLS.indexOf(word[word.length - 1]) != -1) {
      lastSymbol += word[word.length - 1];
      word = word.slice(0, word.length - 1);
    }

    if (onlyEmoji) {
      firstSymbol = lastSymbol = ''
    }

    let translated = getEmojiForWord(word);
    if (translated) {
      translation += firstSymbol + translated + lastSymbol + ' ';
    } else if (!onlyEmoji){
      translation += firstSymbol + word + lastSymbol +  ' '
    }
  }
  return translation;
}
function translate(sentence, onlyEmoji) {
  let translation = '';
  let words = sentence.split(' ');
  for (let i = 0; i < words.length; i++ ) {
    // Punctuation blows. Get all the punctuation at the start and end of the word.
    // TODO: stop copy pasting this.
    let firstSymbol = '';
    let lastSymbol = '';
    var word = words[i];

    while (SYMBOLS.indexOf(word[0]) != -1) {
      firstSymbol += word[0];
      word = word.slice(1, word.length);
    }
    while (SYMBOLS.indexOf(word[word.length - 1]) != -1) {
      lastSymbol += word[word.length - 1];
      word = word.slice(0, word.length - 1);
    }

    if (onlyEmoji) {
      firstSymbol = lastSymbol = ''
    }

    let translated = getEmojiForWord(word);
    if (translated) {
      translation += firstSymbol + translated + lastSymbol + ' ';
    } else if (!onlyEmoji){
      translation += firstSymbol + word + lastSymbol +  ' '
    }
  }
  return translation;
}
function translate ( sentence , onlyEmoji ) { let translation = '' ; let words = sentence . split ( ' ' ) ; for ( let i = 0 ; i < words . length ; i ++ ) { // Punctuation blows. Get all the punctuation at the start and end of the word. // TODO: stop copy pasting this. let firstSymbol = '' ; let lastSymbol = '' ; var word = words [ i ] ; while ( SYMBOLS . indexOf ( word [ 0 ] ) != - 1 ) { firstSymbol += word [ 0 ] ; word = word . slice ( 1 , word . length ) ; } while ( SYMBOLS . indexOf ( word [ word . length - 1 ] ) != - 1 ) { lastSymbol += word [ word . length - 1 ] ; word = word . slice ( 0 , word . length - 1 ) ; } if ( onlyEmoji ) { firstSymbol = lastSymbol = '' } let translated = getEmojiForWord ( word ) ; if ( translated ) { translation += firstSymbol + translated + lastSymbol + ' ' ; } else if ( ! onlyEmoji ) { translation += firstSymbol + word + lastSymbol + ' ' } } return translation ; }
Translates an entire sentence to emoji. If multiple translations exist
for a particular word, a random emoji is picked.
@param {String} sentence The sentence to be translated
@param {Bool} onlyEmoji True if the translation should omit all untranslatable words
@returns {String} An emoji translation!
Translates an entire sentence to emoji . If multiple translations exist for a particular word a random emoji is picked .