UNPKG

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