-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from aruznieto/i18n
feat: i18n - dynamic import on build time
- Loading branch information
Showing
9 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"code": "en", | ||
"name": "English" | ||
}, | ||
{ | ||
"code": "es-ES", | ||
"name": "Español" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"code": "en", | ||
"name": "English" | ||
}, | ||
{ | ||
"code": "es-ES", | ||
"name": "Español" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import * as url from "url"; | ||
|
||
const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); | ||
|
||
export default function GenerateLocalesPlugin() { | ||
return { | ||
name: "generate-locales", | ||
buildStart() { | ||
const localesDir = path.resolve(__dirname, "public", "locales"); | ||
|
||
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 = JSON.parse( | ||
fs.readFileSync(commonFilePath, "utf-8") | ||
); | ||
return { | ||
code: locale, | ||
name: commonFile.languageName || locale, | ||
}; | ||
} | ||
return { | ||
code: locale, | ||
name: locale, | ||
}; | ||
}); | ||
|
||
// Save the array to a JSON file | ||
const outputPath = path.resolve( | ||
__dirname, | ||
"src", | ||
"generated", | ||
"localesList.json" | ||
); | ||
fs.writeFileSync(outputPath, JSON.stringify(localesList, null, 2)); | ||
|
||
console.log(`Locales list saved to ${outputPath}`); | ||
} else { | ||
console.error("Locales directory not found."); | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters