1 | import fs from 'node:fs';
|
2 | import path from 'node:path';
|
3 |
|
4 | import {DEFAULT_LANGUAGE} from './index.js';
|
5 |
|
6 | const getSystemLang = () => {
|
7 | let {locale} = new Intl.DateTimeFormat().resolvedOptions();
|
8 | try {
|
9 | locale = locale.slice(0, 2);
|
10 | } catch {
|
11 | console.info(`Couldn't get system language. Setting default: ${DEFAULT_LANGUAGE}`);
|
12 | locale = DEFAULT_LANGUAGE;
|
13 | }
|
14 |
|
15 | return locale;
|
16 | };
|
17 |
|
18 | const createFolders = fullPath => {
|
19 | const dir = path.dirname(fullPath);
|
20 | if (!fs.existsSync(dir)) {
|
21 | const result = fs.mkdirSync(dir, {recursive: true});
|
22 | console.log('Created output path:', result);
|
23 | }
|
24 | };
|
25 |
|
26 | export {getSystemLang, createFolders};
|