2
2
mirror of https://github.com/Thream/website.git synced 2024-07-21 09:28:32 +02:00
website/generators/language/index.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

const fs = require("node:fs")
2021-10-24 05:48:06 +02:00
const prettier = require("prettier")
2021-10-24 05:48:06 +02:00
/**
* @param {import('plop').NodePlopAPI} plop
* @returns {import('node-plop').PlopGeneratorConfig}
*/
exports.languageGenerator = (plop) => {
return {
description: "Add a new language for translations",
2021-10-24 05:48:06 +02:00
prompts: [
{
type: "input",
name: "locale",
message: "locale",
},
2021-10-24 05:48:06 +02:00
],
actions: [
{
type: "addMany",
base: "locales/en",
destination: "locales/{{locale}}",
templateFiles: "locales/en/**",
2021-10-24 05:48:06 +02:00
},
async (answers) => {
process.chdir(plop.getPlopfilePath())
const data = JSON.parse(
await fs.promises.readFile("i18n.json", { encoding: "utf-8" }),
2021-10-24 05:48:06 +02:00
)
data.locales.push(answers.locale)
const formatted = prettier.format(JSON.stringify(data, null, 2), {
filepath: "i18n.json",
2021-10-24 05:48:06 +02:00
})
await fs.promises.writeFile("i18n.json", formatted, {
encoding: "utf-8",
2021-10-24 05:48:06 +02:00
})
return plop.renderString(
`
Added '{{locale}}' to the 'locales' array inside 'i18n.json'
Don't forget to add the flag at 'public/images/svg/languages/{{locale}}.svg'
`,
answers,
2021-10-24 05:48:06 +02:00
)
},
],
2021-10-24 05:48:06 +02:00
}
}