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(' ')
}
)
translateText() {
try{
translate(this.text, { to: this.translateTo }).then(res => {
this.translatedText = res.text;
});
}catch(e){
console.error(e);
}
},
.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)
}
async function words(q, params) {
return translate(q, { ...params })
.then(res => res.text)
.catch(err => log.error(err));
}