mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-07-16 10:03:12 -07:00
feat: dynamic import on build time
This commit is contained in:
parent
ee73374c29
commit
6978495963
8 changed files with 67 additions and 15 deletions
40
generateLocalesList.js
Normal file
40
generateLocalesList.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const localesDir = path.join(__dirname, "frontend", "public", "locales"); // Adjust the path if necessary
|
||||
|
||||
if (fs.existsSync(localesDir)) {
|
||||
const localesList = fs
|
||||
.readdirSync(localesDir)
|
||||
.filter((file) => {
|
||||
return fs.statSync(path.join(localesDir, file)).isDirectory();
|
||||
})
|
||||
.map((locale) => {
|
||||
const commonFilePath = path.join(localesDir, locale, "common.json");
|
||||
if (fs.existsSync(commonFilePath)) {
|
||||
const commonFile = require(commonFilePath);
|
||||
return {
|
||||
code: locale,
|
||||
name: commonFile.yourLanguage || locale,
|
||||
};
|
||||
}
|
||||
return {
|
||||
code: locale,
|
||||
name: locale,
|
||||
};
|
||||
});
|
||||
|
||||
// Save the array to a JSON file
|
||||
const outputPath = path.join(
|
||||
__dirname,
|
||||
"frontend",
|
||||
"src",
|
||||
"utils",
|
||||
"localesList.json"
|
||||
);
|
||||
fs.writeFileSync(outputPath, JSON.stringify(localesList, null, 2));
|
||||
|
||||
console.log(`Locales list saved to ${outputPath}`);
|
||||
} else {
|
||||
console.error("Locales directory not found.");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue