app/autotranslate/server/googleTranslate.js
/**
	 * Returns translated message attachment description in target languages.
	 * @private
	 * @param {object} attachment
	 * @param {object} targetLanguages
	 * @returns {object} translated attachment descriptions for each target language
	 */
Returns translated message attachment description in target languages.
@private
@param {object} attachment
@param {object} targetLanguages
@returns {object} translated attachment descriptions for each target language
Returns translated message attachment description in target languages . @private @param { object } attachment @param { object } targetLanguages @returns { object } translated attachment descriptions for each target language
_translateAttachmentDescriptions(attachment, targetLanguages) {
		const translations = {};
		const query = `q=${ encodeURIComponent(attachment.description || attachment.text) }`;
		const supportedLanguages = this.getSupportedLanguages('en');
		targetLanguages.forEach((language) => {
			if (language.indexOf('-') !== -1 && !_.findWhere(supportedLanguages, { language })) {
				language = language.substr(0, 2);
			}
			try {
				const result = HTTP.get(this.apiEndPointUrl, {
					params: {
						key: this.apiKey,
						target: language,
					},
					query,
				});
				if (result.statusCode === 200 && result.data && result.data.data && result.data.data.translations && Array.isArray(result.data.data.translations) && result.data.data.translations.length > 0) {
					translations[language] = result.data.data.translations.map((translation) => translation.translatedText).join('\n');
				}
			} catch (e) {
				SystemLogger.error('Error translating message', e);
			}
		});
		return translations;
	}
_translateAttachmentDescriptions ( attachment , targetLanguages ) { const translations = { } ; const query = ` ${ encodeURIComponent ( attachment . description || attachment . text ) } ` ; const supportedLanguages = this . getSupportedLanguages ( 'en' ) ; targetLanguages . forEach ( ( language ) => { if ( language . indexOf ( '-' ) !== - 1 && ! _ . findWhere ( supportedLanguages , { language } ) ) { language = language . substr ( 0 , 2 ) ; } try { const result = HTTP . get ( this . apiEndPointUrl , { params : { key : this . apiKey , target : language , } , query , } ) ; if ( result . statusCode === 200 && result . data && result . data . data && result . data . data . translations && Array . isArray ( result . data . data . translations ) && result . data . data . translations . length > 0 ) { translations [ language ] = result . data . data . translations . map ( ( translation ) => translation . translatedText ) . join ( '\n' ) ; } } catch ( e ) { SystemLogger . error ( 'Error translating message' , e ) ; } } ) ; return translations ; }
Returns translated message attachment description in target languages.
Returns translated message attachment description in target languages .