next-intl
Version:
Internationalization (i18n) for Next.js
2 lines (1 loc) • 1.13 kB
JavaScript
import e from"fs";import s from"path";import{throwError as t}from"./utils.js";import o from"./watchFile.js";function n(o){var n;["dev","build","typegen"].some((e=>process.argv.includes(e)))&&(n=()=>{for(const n of o){const o=s.resolve(n);e.existsSync(o)||t(`\`createMessagesDeclaration\` points to a non-existent file: ${o}`),o.endsWith(".json")||t(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${o}`);const c=process.env["NODE_ENV".trim()];r(n),"development"===c&&i(n)}},"1"!==process.env._NEXT_INTL_COMPILE_MESSAGES&&(process.env._NEXT_INTL_COMPILE_MESSAGES="1",n()))}function i(e){const s=o(e,(()=>{r(e,!0)}));process.on("exit",(()=>{s.close()}))}function r(s,t=!1){const o=s.replace(/\.json$/,".d.json.ts");function n(e){return`// This file is auto-generated by next-intl, do not edit directly.\n// See: https://next-intl.dev/docs/workflows/typescript#messages-arguments\n\ndeclare const messages: ${e.trim()};\nexport default messages;`}if(t)return e.promises.readFile(s,"utf-8").then((s=>e.promises.writeFile(o,n(s))));const i=e.readFileSync(s,"utf-8");e.writeFileSync(o,n(i))}export{n as default};