How to use @vitalets/google-translate-api - 8 common examples

To help you get started, we’ve selected a few @vitalets/google-translate-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nikersify / alfred-polyglot / lib / cmd / translate.js View on Github external
const translateCommand = async input => {
	const parsed = parse(input)

	for (const prefix of ['from', 'to']) {
		const subject = parsed[prefix]

		if (subject === undefined) {
			continue
		}

		if (subject === $pending || !languages.getCode(subject)) {
			const out = outputLanguages(
				subject === $pending ? null : subject,
				lang => {
					const code = languages.getCode(lang)
					const sliceBy = subject === $pending ? undefined : -1
					return input.trim().split(' ').slice(0, sliceBy).concat(code).join(' ')
				}
			)

			if (out) {
				return out
			}
		}
	}

	if (parsed.text.length === 0) {
github nikersify / alfred-polyglot / lib / cmd / translate.js View on Github external
lang => {
					const code = languages.getCode(lang)
					const sliceBy = subject === $pending ? undefined : -1
					return input.trim().split(' ').slice(0, sliceBy).concat(code).join(' ')
				}
			)
github Janglee123 / eplee / src / renderer / components / Reader / BubleMenu.vue View on Github external
translateText() {
			try{
				translate(this.text, { to: this.translateTo }).then(res => {
					this.translatedText = res.text;
      	});
			}catch(e){
				console.error(e);
			}
    },
github nikersify / alfred-polyglot / lib / output / languages.js View on Github external
.map(name => ({
			title: name.slice(0, 1).toUpperCase() + name.slice(1),
			autocomplete: autocomplete(name),
			valid: false,
			icon: {
				path: `icons/${languages.getCode(name)}.png`
			}
		}))
github nikersify / alfred-polyglot / lib / cmd / translate.js View on Github external
}
			)

			if (out) {
				return out
			}
		}
	}

	if (parsed.text.length === 0) {
		return [{
			title: 'Translate \'...\''
		}]
	}

	const from = languages.getCode(parsed.from) || 'auto'
	const to = languages.getCode(parsed.to || alfy.config.get('default-language'))

	return translate(parsed.text, from, to)
}
github nikersify / alfred-polyglot / lib / cmd / translate.js View on Github external
)

			if (out) {
				return out
			}
		}
	}

	if (parsed.text.length === 0) {
		return [{
			title: 'Translate \'...\''
		}]
	}

	const from = languages.getCode(parsed.from) || 'auto'
	const to = languages.getCode(parsed.to || alfy.config.get('default-language'))

	return translate(parsed.text, from, to)
}
github ant-tool / atool-l10n / src / plugins / google.js View on Github external
async function words(q, params) {
  return translate(q, { ...params })
    .then(res => res.text)
    .catch(err => log.error(err));
}

@vitalets/google-translate-api

A free and unlimited API for Google Translate

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis