Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key: \"getTranslate\",
- value: function getTranslate(args) {
- // Don't remake the request if we already have the value.
- if (this._lastTextTranslated === args.WORDS && this._lastLangTranslated === args.LANGUAGE) {
- return this._translateResult;
- }
- var lang = this.getLanguageCodeFromArg(args.LANGUAGE);
- var urlBase = \"\".concat(serverURL, \"translate?language=\");
- urlBase += lang;
- urlBase += '&text=';
- urlBase += encodeURIComponent(args.WORDS);
- var tempThis = this;
- var translatePromise = new Promise(function (resolve) {
- nets({
- url: urlBase,
- timeout: serverTimeoutMs
- }, function (err, res, body) {
- if (err) {
- log.warn(\"error fetching translate result! \".concat(res));
- resolve('');
- return '';
- }
- var translated = JSON.parse(body).result;
- tempThis._translateResult = translated; // Cache what we just translated so we don't keep making the
- // same call over and over.
- tempThis._lastTextTranslated = args.WORDS;
- tempThis._lastLangTranslated = args.LANGUAGE;
- resolve(translated);
- return translated;
- });
- });
- translatePromise.then(function (translatedText) {
- return translatedText;
- });
- return translatePromise;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement