-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexternal-apis.js
51 lines (45 loc) · 1.12 KB
/
external-apis.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
'use babel'
let path = null
let fs = null
let isInitialized = false
function initialize() {
if (isInitialized) return
path = require('path')
fs = require('fs')
isInitialized = true
}
export default class ExternalApis {
constructor(pathes) {
let translatorsPath = `${atom.getConfigDirPath()}/translators`
let dictionariesPath = `${atom.getConfigDirPath()}/dictionaries`
if (pathes) {
if (pathes.translatorsPath) {
translatorsPath = pathes.translatorsPath
}
if (pathes.dictionariesPath) {
translatorsPath = pathes.dictionariesPath
}
}
try {
this.translators = require(translatorsPath)
} catch (e) {
this.translators = []
}
try {
this.dictionaries = require(dictionariesPath)
} catch (e) {
this.dictionaries = []
}
}
load(translatorPlusDictionary) {
// Add external APIs into TranslatorPlusDictionary
Array.prototype.push.apply(
translatorPlusDictionary.translators,
this.translators
)
Array.prototype.push.apply(
translatorPlusDictionary.dictionaries,
this.dictionaries
)
}
}