Skip to content

Commit e56c800

Browse files
committed
polish
1 parent 6463dc2 commit e56c800

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

index.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function doTranslate() {
8282
// Input
8383
items.push({
8484
title: fromText,
85-
subtitle: `Phonetic: ${fromPhonetic || ''}`,
85+
subtitle: `Phonetic: ${fromPhonetic}`,
8686
quicklookurl: `${g_config.domain}/#view=home&op=translate&sl=${g_config.from.lang}&tl=${g_config.to.lang}&text=${encodeURIComponent(fromText)}`,
8787
arg: fromArg,
8888
text: {
@@ -100,7 +100,7 @@ function doTranslate() {
100100
// Translation
101101
items.push({
102102
title: toText,
103-
subtitle: `Phonetic: ${toPhonetic || ''}`,
103+
subtitle: `Phonetic: ${toPhonetic}`,
104104
quicklookurl: `${g_config.domain}/#view=home&op=translate&sl=${g_config.to.lang}&tl=${g_config.from.lang}&text=${encodeURIComponent(toText)}`,
105105
arg: toArg,
106106
text: {
@@ -113,33 +113,28 @@ function doTranslate() {
113113
});
114114

115115
// Definitions
116-
if (res.to.definitions.length > 0) {
117-
res.to.definitions.forEach(definition => {
118-
items.push({
119-
title: `Definition[${definition.partsOfSpeech}]: ${definition.value}`,
120-
subtitle: `Example: ${definition.example || ''}`,
121-
quicklookurl: `${g_config.domain}/#view=home&op=translate&sl=${g_config.from.lang}&tl=${g_config.to.lang}&text=${encodeURIComponent(fromText)}`,
122-
text: {
123-
copy: definition.value,
124-
largetype: `Definitions: ${definition.value}\n\nExample: ${definition.example || ''}`
125-
}
126-
});
116+
res.to.definitions.forEach(definition => {
117+
items.push({
118+
title: `Definition[${definition.partsOfSpeech}]: ${definition.value}`,
119+
subtitle: `Example: ${definition.example}`,
120+
text: {
121+
copy: definition.value,
122+
largetype: `Definition: ${definition.value}\n\nExample: ${definition.example}`
123+
}
127124
});
128-
}
125+
});
129126

130127
// Translation Of
131-
if (res.to.translations.length > 0) {
132-
res.to.translations.forEach(translation => {
133-
items.push({
134-
title: `Translation[${translation.partsOfSpeech}]: ${translation.value}`,
135-
subtitle: `Frequency: ${translation.frequency ? translation.frequency.toFixed(4) : '0.0000'} Synonyms: ${translation.synonyms ? translation.synonyms.join(', ') : ''}`,
136-
text: {
137-
copy: translation.value,
138-
largetype: `${translation.value}\n\nSynonyms: ${translation.synonyms ? translation.synonyms.join(', ') : ''}`
139-
}
140-
});
128+
res.to.translations.forEach(translation => {
129+
items.push({
130+
title: `Translation[${translation.partsOfSpeech}]: ${translation.value}`,
131+
subtitle: `Frequency: ${translation.frequency.toFixed(4)} Synonyms: ${translation.synonyms}`,
132+
text: {
133+
copy: translation.value,
134+
largetype: `Translation: ${translation.value}\n\nSynonyms: ${translation.synonyms}`
135+
}
141136
});
142-
}
137+
});
143138
}
144139

145140
alfy.output(items);

translate.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ function translate(text, opts) {
4242
text: {
4343
array: [],
4444
value: '',
45-
phonetic: null
45+
phonetic: ''
4646
}
4747
},
4848
to: {
4949
text: {
5050
array: [],
5151
value: '',
52-
phonetic: null
52+
phonetic: ''
5353
},
5454
translations: [],
5555
definitions: []
@@ -107,9 +107,9 @@ function translate(text, opts) {
107107
var partsOfSpeech = obj[0];
108108
obj[1].forEach(function (obj) {
109109
result.to.definitions.push({
110-
partsOfSpeech: partsOfSpeech,
111-
value: obj[0],
112-
example: obj[2]
110+
partsOfSpeech: partsOfSpeech || '',
111+
value: obj[0] || '',
112+
example: obj[2] || ''
113113
});
114114
});
115115
});
@@ -121,10 +121,10 @@ function translate(text, opts) {
121121
var partsOfSpeech = obj[0];
122122
obj[2].forEach(function (obj) {
123123
result.to.translations.push({
124-
partsOfSpeech: partsOfSpeech,
125-
value: obj[0],
126-
synonyms: obj[1],
127-
frequency: obj[3]
124+
partsOfSpeech: partsOfSpeech || '',
125+
value: obj[0] || '',
126+
synonyms: obj[1] || [],
127+
frequency: obj[3] || 0.0000
128128
});
129129
});
130130
});

0 commit comments

Comments
 (0)