forked from docsifyjs/docsify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (33 loc) · 766 Bytes
/
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
'use strict'
const path = require('path')
const Y18n = require('y18n')
const fse = require('fs-extra')
class Locales {
constructor () {
this.y18n = Y18n({
directory: path.resolve(__dirname),
updateFiles: false,
locale: this.detectLocale()
})
}
detectLocale () {
const yargs = require('yargs')
const locale = yargs.locale()
try {
this._existsLocaleFile(locale)
} catch (e) {
return 'en'
}
return locale
}
_existsLocaleFile (locale) {
return fse.readJsonSync(path.join(__dirname, `${locale.substring(0, 2)}.json`))
}
__ (str) {
return this.y18n.__(str)
}
__n (singular, plural, count) {
return this.y18n.__n(singular, plural, count)
}
}
module.exports = Locales