1 | const fs = require('fs-extra')
|
2 | const path = require('path')
|
3 | const osLocale = require('os-locale')
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | module.exports = () => {
|
10 | const locale = osLocale.sync()
|
11 | let pathname
|
12 |
|
13 | pathname = path.resolve(__dirname, `../locales/${locale}.json`)
|
14 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname)
|
15 |
|
16 | pathname = path.resolve(__dirname, `../locales/${locale.toLowerCase()}.json`)
|
17 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname)
|
18 |
|
19 | pathname = path.resolve(__dirname, `../locales/${locale.replace(/_/g, '-')}.json`)
|
20 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname)
|
21 |
|
22 | pathname = path.resolve(__dirname, `../locales/${locale.replace(/_/g, '-').toLowerCase()}.json`)
|
23 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname)
|
24 |
|
25 | pathname = path.resolve(__dirname, `../locales/${locale.split('_')[0]}.json`)
|
26 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname)
|
27 |
|
28 | pathname = path.resolve(__dirname, `../locales/en.json`)
|
29 | return fs.readJsonSync(pathname)
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | }
|