-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathremoveMultilang.js
72 lines (64 loc) · 2.06 KB
/
removeMultilang.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const fs = require("fs");
const path = require("path");
const languages = require("../src/config/language.json");
// Filter out the English language
const englishLang = languages.filter((item) => item.languageCode === "en");
const filterLangs = languages.filter((item) => item.languageCode !== "en");
const contentDir = "src/content";
const configDir = "src/config";
const i18nDir = "src/i18n";
// Update language.json to only include the English language
fs.writeFileSync(
path.join(configDir, "language.json"),
JSON.stringify(englishLang, null, 2),
);
// Remove content directories for languages other than English
filterLangs.forEach((lang) => {
const langContentDir = path.join(contentDir, lang.contentDir);
fs.rm(langContentDir, { recursive: true, force: true }, (err) => {
if (err) {
console.error(`Error deleting folder ${langContentDir}:`, err);
return;
}
console.log(`Folder ${langContentDir} deleted successfully`);
});
});
// Remove other menu.{lang}.json files except menu.en.json
fs.readdir(configDir, (err, files) => {
if (err) {
console.error("Error reading config directory:", err);
return;
}
files.forEach((file) => {
if (file.startsWith("menu.") && file !== "menu.en.json") {
const filePath = path.join(configDir, file);
fs.unlink(filePath, (err) => {
if (err) {
console.error(`Error deleting file ${filePath}:`, err);
return;
}
console.log(`File ${filePath} deleted successfully`);
});
}
});
});
// Remove other language files from i18n folder except en.json
fs.readdir(i18nDir, (err, files) => {
if (err) {
console.error("Error reading i18n directory:", err);
return;
}
files.forEach((file) => {
if (file !== "en.json") {
const filePath = path.join(i18nDir, file);
fs.unlink(filePath, (err) => {
if (err) {
console.error(`Error deleting file ${filePath}:`, err);
return;
}
console.log(`File ${filePath} deleted successfully`);
});
}
});
});
console.log("Cleanup completed.");