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