Skip to content

Commit

Permalink
feat(i18n): added missing locale files in tools (CorentinTh#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinTh authored Feb 1, 2024
1 parent 1334bff commit 7f5fa00
Show file tree
Hide file tree
Showing 312 changed files with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions scripts/build-locales-files.mjs
Original file line number Diff line number Diff line change
@@ -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(),
);
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added src/tools/bcrypt/locales/fr.yml
Empty file.
Empty file added src/tools/bcrypt/locales/pt.yml
Empty file.
Empty file added src/tools/bcrypt/locales/uk.yml
Empty file.
Empty file added src/tools/bcrypt/locales/zh.yml
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit 7f5fa00

Please sign in to comment.