-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
141 lines (135 loc) · 4.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"use strict";
const alfy = require('alfy');
const language = require('./languages.js');
const configstore = require('configstore');
const languagePair = new configstore('language-config-pair');
const q = alfy.input;
var items = [];
if (q === 'ls') {
var pair = 'Not';
if (languagePair.get('pair')) {
pair = languagePair.get('pair').join('&');
} else if (languagePair.get('source') && languagePair.get('target')) {
pair = `${languagePair.get('source')}>${languagePair.get('target')}`;
}
items.push({
title: `Current, [${pair}] assigned.`
});
} else if (q.indexOf('>') === -1 && q.indexOf('&') === -1) {
items.push({
title: `Failure, must contain \'>\' or\' &\'`,
subtitle: `configuration format: source>target or first one&the second.`,
icon: {
path: alfy.icon.error
}
});
} else if (q.indexOf('>') !== -1 && q.indexOf('&') !== -1) {
items.push({
title: `Failure, \'>\' or \'&\' must contain only one.`,
subtitle: `configuration format: source>target or first one&the second.`,
icon: {
path: alfy.icon.error
}
});
} else if (q.indexOf('>') === -1) {
// auto
var pair = q.split('&');
if (pair.length !== 2) {
items.push({
title: `Failure, \'&\' must contain only one.`,
subtitle: `configuration format: first one&the second.`,
icon: {
path: alfy.icon.error
}
});
} else {
var pair0 = language.getCode(pair[0]);
var pair1 = language.getCode(pair[1]);
if (!pair0 && !pair1) {
items.push({
title: `Failure, first[${pair[0]}] and second[${pair[1]}] languages not supported.`,
subtitle: `Press shift to see full support languages.`,
quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme',
icon: {
path: alfy.icon.error
}
});
} else if (!pair0) {
items.push({
title: `Failure, first[${pair[0]}] language not supported.`,
subtitle: `Press shift to see full support languages.`,
quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme',
icon: {
path: alfy.icon.error
}
});
} else if (!pair1) {
items.push({
title: `Failure, second[${pair[1]}] language not supported.`,
subtitle: `Press shift to see full support languages.`,
quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme',
icon: {
path: alfy.icon.error
}
});
} else {
languagePair.delete('source');
languagePair.delete('target');
languagePair.set('pair', pair);
items.push({
title: `Success, [${q}] assigned.`
});
}
}
} else {
// manual
var pair = q.split('>');
if (pair.length !== 2) {
items.push({
title: `Failure, \'>\' must contain only one.`,
subtitle: `configuration format: source>target or first one&the second.`,
icon: {
path: alfy.icon.error
}
});
} else {
var pair0 = language.getCode(pair[0]);
var pair1 = language.getCode(pair[1]);
if (!pair0 && !pair1) {
items.push({
title: `Failure, source[${pair[0]}] and target[${pair[1]}] languages not supported.`,
subtitle: `Press shift to see full support languages.`,
quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme',
icon: {
path: alfy.icon.error
}
});
} else if (!pair0) {
items.push({
title: `Failure, source[${pair[0]}] language not supported.`,
subtitle: `Press shift to see full support languages.`,
quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme',
icon: {
path: alfy.icon.error
}
});
} else if (!pair1) {
items.push({
title: `Failure, target[${pair[1]}] language not supported.`,
subtitle: `Press shift to see full support languages.`,
quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme',
icon: {
path: alfy.icon.error
}
});
} else {
languagePair.delete('pair');
languagePair.set('source', pair0);
languagePair.set('target', pair1);
items.push({
title: `Success, [${q}] assigned.`
});
}
}
}
alfy.output(items);