diff --git a/examples/translator.js b/examples/translator.js index 0414506..010baf6 100644 --- a/examples/translator.js +++ b/examples/translator.js @@ -8,7 +8,7 @@ const InputStreamReader = Java.type("java.io.InputStreamReader"); const script = registerScript({ name: "Translator", version: "1.0.8", - authors: ["Trikaes"], + authors: ["Trikaes", "1zuna"], }); script.registerCommand({ @@ -28,17 +28,19 @@ script.registerCommand({ description: "The target language code (en, fr, de, etc...)", }, { - name: "word", + name: "text", type: "string", required: true, - description: "The word to translate", + vararg: true, + description: "The text to translate", }, ], - onExecute(sourceLanguage, targetLanguage, word) { + onExecute(sourceLanguage, targetLanguage, text) { try { + var text = text.join(" "); const url = new URL( `https://translate.googleapis.com/translate_a/single?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t&q=${encodeURIComponent( - word + text )}` ); // finally got this to work @@ -66,15 +68,15 @@ script.registerCommand({ const translatedText = jsonResponse[0][0][0]; Client.displayChatMessage( - `§cTranslation §7(§c${sourceLanguage} §7to §c${targetLanguage}§7): §c${word} §7-> §c${translatedText}` + `§cTranslation §7(§c${sourceLanguage} §7to §c${targetLanguage}§7): §c${text} §7-> §c${translatedText}` ); // cool colors } else { Client.displayChatMessage( - `§4failed to translate word '${word}'. response code: ${responseCode}` + `§4failed to translate text '${text}'. response code: ${responseCode}` ); // hope i dont get this } } catch (error) { - Client.displayChatMessage(`§4error translating word '${word}': ${error}`); // hope i dont get this + Client.displayChatMessage(`§4error translating text '${text}': ${error}`); // hope i dont get this } }, });