alfred-polyglot
Advanced tools
Comparing version 1.1.5 to 1.2.0
@@ -6,4 +6,7 @@ const alfy = require('alfy') | ||
const outputLanguages = require('../output/languages') | ||
const {CachedList} = require('../util') | ||
module.exports = async input => { | ||
const history = new CachedList('to-lang-history') | ||
const translateCommand = async input => { | ||
const originalWords = input.trim().split(' ') | ||
@@ -82,5 +85,16 @@ const words = originalWords.slice(0) | ||
if (res.from.language.iso.toLowerCase() === to) { | ||
const lastUniqueToLanguage = history.all.reverse() | ||
.find(l => l !== to) | ||
const newToLanguage = lastUniqueToLanguage || 'en' | ||
return translateCommand(`to ${newToLanguage} ` + input) | ||
} | ||
history.append(to) | ||
const messages = [] | ||
let fromLangMsg = languages[res.from.language.iso] | ||
let fromLangMsg = languages[res.from.language.iso.toLowerCase()] | ||
const toLangMsg = languages[to] | ||
@@ -138,2 +152,4 @@ | ||
module.exports = translateCommand | ||
module.exports.meta = { | ||
@@ -140,0 +156,0 @@ name: 'Translate text', |
@@ -0,1 +1,2 @@ | ||
const alfy = require('alfy') | ||
const languages = require('google-translate-api/languages') | ||
@@ -14,1 +15,22 @@ | ||
.map(x => x.toLowerCase()) | ||
module.exports.CachedList = class CachedList { | ||
constructor(key) { | ||
this.key = key | ||
if (!alfy.cache.has(this.key)) { | ||
alfy.cache.set(this.key, []) | ||
} | ||
} | ||
get all() { | ||
return alfy.cache.get(this.key) | ||
} | ||
append(item) { | ||
const old = alfy.cache.get(this.key) | ||
alfy.cache.set(this.key, old.concat(item)) | ||
return this | ||
} | ||
} |
{ | ||
"name": "alfred-polyglot", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"description": "Translate text with ease using Google Translate", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
1244027
325