UNPKG

1.25 kBJavaScriptView Raw
1const fs = require('fs-extra')
2const path = require('path')
3const osLocale = require('os-locale')
4
5module.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 // const l = fs.existsSync(path.resolve(__dirname, `../locales/${locale.toLowerCase()}.js`))
28 // ? require(`../locales/${locale.toLowerCase()}`)
29 // : require(`../locales/en_us`)
30 // return l
31}