How to use the @vitalets/google-translate-api/languages.getCode function in @vitalets/google-translate-api

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 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)
}

@vitalets/google-translate-api

A free and unlimited API for Google Translate

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis