-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi18next.config.mjs
More file actions
54 lines (49 loc) · 1.79 KB
/
i18next.config.mjs
File metadata and controls
54 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import fs from "fs";
import path from "path";
const I18N_DIRECTORY = "i18n-locales";
// Function to read filenames in a directory and filter them by pattern synchronously
function readLocaleFilenamesSync(directory) {
try {
const files = fs.readdirSync(directory);
// Filter files to match only .js files and remove the extension
const locales = files
.filter((file) => file.endsWith(".js"))
.map((file) => path.basename(file, ".js"));
return locales;
} catch (error) {
console.error("Error reading locale filenames:", error);
return [];
}
}
// Assuming this file is located at the root of your project
// Adjust the path to your i18n directory accordingly
const srcDirectory = path.join(process.cwd(), process.env.SRC_DIRECTORY || "");
export const i18nDirectory = path.join(srcDirectory, I18N_DIRECTORY);
if (!fs.existsSync(i18nDirectory)) {
// Recursive option ensures that all directories are created along the path if they don't exist
fs.mkdirSync(i18nDirectory, { recursive: true });
console.log(`Directory ${i18nDirectory} was created.`);
console.log(
`Now you need to add [LOCALE].js files there with translations and run this command again.`
);
}
// Use the synchronous function to set locales
const locales = readLocaleFilenamesSync(i18nDirectory);
export { locales };
export default {
lexers: {
mjs: ["JavascriptLexer"],
js: ["JavascriptLexer"],
ts: ["JavascriptLexer"],
jsx: ["JsxLexer"],
tsx: ["JsxLexer"],
},
locales,
//relative to process.cwd() - or better use absolute paths
output: path.join(srcDirectory, I18N_DIRECTORY, "$LOCALE.keys.json"),
//relative to this file - or better use absolute paths
input: [
path.join(srcDirectory, "**", "*.{ts,tsx}"),
"!" + path.join(srcDirectory, "node_modules", "**"),
],
};