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(
|
17 | __dirname,
|
18 | `../locales/${locale.toLowerCase()}.json`
|
19 | );
|
20 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname);
|
21 |
|
22 | pathname = path.resolve(
|
23 | __dirname,
|
24 | `../locales/${locale.replace(/-/g, '_')}.json`
|
25 | );
|
26 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname);
|
27 |
|
28 | pathname = path.resolve(
|
29 | __dirname,
|
30 | `../locales/${locale.replace(/-/g, '_').toLowerCase()}.json`
|
31 | );
|
32 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname);
|
33 |
|
34 | pathname = path.resolve(
|
35 | __dirname,
|
36 | `../locales/${locale.split('-')[0]}.json`
|
37 | );
|
38 | if (fs.existsSync(pathname)) return fs.readJsonSync(pathname);
|
39 |
|
40 | pathname = path.resolve(__dirname, `../locales/en.json`);
|
41 | return fs.readJsonSync(pathname);
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | };
|