UNPKG

631 BJavaScriptView Raw
1import fs from 'node:fs';
2import path from 'node:path';
3
4import {DEFAULT_LANGUAGE} from './index.js';
5
6const 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
18const 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
26export {getSystemLang, createFolders};