Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
lang => {
const code = languages.getCode(lang)
const sliceBy = subject === $pending ? undefined : -1
return input.trim().split(' ').slice(0, sliceBy).concat(code).join(' ')
}
)
.map(name => ({
title: name.slice(0, 1).toUpperCase() + name.slice(1),
autocomplete: autocomplete(name),
valid: false,
icon: {
path: `icons/${languages.getCode(name)}.png`
}
}))
}
)
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)
}
)
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)
}