1
0
Fork 0
mirror of https://github.com/CorentinTh/it-tools.git synced 2025-08-10 07:55:19 +02:00

feat(i18n): added missing locale files in tools

This commit is contained in:
Corentin Thomasset 2024-02-01 17:58:57 +01:00
parent 1334bff30a
commit ae8b0eb44e
No known key found for this signature in database
GPG key ID: DBD997E935996158
312 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,61 @@
import { existsSync, writeFileSync } from 'node:fs';
import { Glob } from 'bun';
import _ from 'lodash';
async function getPathsFromGlobs({ patterns, onlyFiles = true }) {
const filePaths = [];
for (const pattern of patterns) {
const glob = new Glob(pattern);
for await (const filePath of glob.scan({ onlyFiles, cwd: '.' })) {
filePaths.push(filePath);
}
}
return { filePaths };
}
function getLocaleKey({ filePath }) {
const fileName = filePath.split('/').pop();
return fileName.replace(/\.yml$/, '');
}
async function createMissingLocaleFile({ localeKey }) {
const fileName = `${localeKey}.yml`;
const { filePaths: localesDirs } = await getPathsFromGlobs({
patterns: [
'locales',
'src/tools/*/locales',
],
onlyFiles: false,
});
for (const localesDir of localesDirs) {
const filePath = `${localesDir}/${fileName}`;
if (existsSync(filePath)) {
console.log(`Locale file already exists: ${filePath}`);
continue;
}
console.log(`Creating missing locale file: ${filePath}`);
writeFileSync(filePath, '', 'utf8');
}
}
const { filePaths } = await getPathsFromGlobs({
patterns: [
'locales/*.yml',
'src/tools/*/locales/*.yml',
],
});
await Promise.all(
_.chain(filePaths)
.map(filePath => getLocaleKey({ filePath }))
.uniq()
.map(localeKey => createMissingLocaleFile({ localeKey }))
.value(),
);

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

Some files were not shown because too many files have changed in this diff Show more