Skip to content

Commit 7f5fa00

Browse files
authored
feat(i18n): added missing locale files in tools (CorentinTh#863)
1 parent 1334bff commit 7f5fa00

File tree

312 files changed

+61
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+61
-0
lines changed

scripts/build-locales-files.mjs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { existsSync, writeFileSync } from 'node:fs';
2+
import { Glob } from 'bun';
3+
import _ from 'lodash';
4+
5+
async function getPathsFromGlobs({ patterns, onlyFiles = true }) {
6+
const filePaths = [];
7+
8+
for (const pattern of patterns) {
9+
const glob = new Glob(pattern);
10+
11+
for await (const filePath of glob.scan({ onlyFiles, cwd: '.' })) {
12+
filePaths.push(filePath);
13+
}
14+
}
15+
16+
return { filePaths };
17+
}
18+
19+
function getLocaleKey({ filePath }) {
20+
const fileName = filePath.split('/').pop();
21+
return fileName.replace(/\.yml$/, '');
22+
}
23+
24+
async function createMissingLocaleFile({ localeKey }) {
25+
const fileName = `${localeKey}.yml`;
26+
27+
const { filePaths: localesDirs } = await getPathsFromGlobs({
28+
patterns: [
29+
'locales',
30+
'src/tools/*/locales',
31+
],
32+
onlyFiles: false,
33+
});
34+
35+
for (const localesDir of localesDirs) {
36+
const filePath = `${localesDir}/${fileName}`;
37+
38+
if (existsSync(filePath)) {
39+
console.log(`Locale file already exists: ${filePath}`);
40+
continue;
41+
}
42+
43+
console.log(`Creating missing locale file: ${filePath}`);
44+
writeFileSync(filePath, '', 'utf8');
45+
}
46+
}
47+
48+
const { filePaths } = await getPathsFromGlobs({
49+
patterns: [
50+
'locales/*.yml',
51+
'src/tools/*/locales/*.yml',
52+
],
53+
});
54+
55+
await Promise.all(
56+
_.chain(filePaths)
57+
.map(filePath => getLocaleKey({ filePath }))
58+
.uniq()
59+
.map(localeKey => createMissingLocaleFile({ localeKey }))
60+
.value(),
61+
);

src/tools/base64-file-converter/locales/fr.yml

Whitespace-only changes.

src/tools/base64-file-converter/locales/pt.yml

Whitespace-only changes.

src/tools/base64-file-converter/locales/uk.yml

Whitespace-only changes.

src/tools/base64-file-converter/locales/zh.yml

Whitespace-only changes.

src/tools/base64-string-converter/locales/fr.yml

Whitespace-only changes.

src/tools/base64-string-converter/locales/pt.yml

Whitespace-only changes.

src/tools/base64-string-converter/locales/uk.yml

Whitespace-only changes.

src/tools/base64-string-converter/locales/zh.yml

Whitespace-only changes.

src/tools/basic-auth-generator/locales/fr.yml

Whitespace-only changes.

0 commit comments

Comments
 (0)