UNPKG

next-intl-split

Version:

A loader for next-intl to split translation files properly.

1 lines 1.51 kB
{"version":3,"file":"index.mjs","sources":["../src/src/merge/index.ts"],"sourcesContent":["import path from 'path';\nimport { existsSync } from 'fs';\n\nimport { loadMessages } from '../load';\nimport { writeMessages } from '../write';\n\nconst isRelativePath = (pathToCheck: string) => pathToCheck.startsWith(`./`);\nconst doesPathExist = (pathToCheck: string) => existsSync(pathToCheck);\n\nexport const mergeMessages = (pathToDictionaries: string) => {\n const pathIsRelative = isRelativePath(pathToDictionaries);\n\n if (!pathIsRelative) {\n throw new Error(\n `Please provide the RELATIVE path to the dictionaries folder. Like, ./src/i18n/dictionaries`\n );\n }\n\n const absolutePath = path.resolve(process.cwd(), pathToDictionaries);\n\n const pathExist = doesPathExist(absolutePath);\n\n if (!pathExist) {\n throw new Error(\n `The provided path to the dictionaries does not exist! ${absolutePath}`\n );\n }\n\n const messages = loadMessages(absolutePath);\n\n writeMessages(absolutePath, messages);\n};\n"],"names":["mergeMessages","pathToDictionaries","startsWith","Error","absolutePath","path","resolve","process","cwd","pathExist","pathToCheck","existsSync","doesPathExist","messages","loadMessages","writeMessages"],"mappings":"wJAMA,MAGaA,EAAiBC,IAG5B,IAFsCA,EAJoBC,WAAW,MAOnE,MAAM,IAAIC,MACR,8FAIJ,MAAMC,EAAeC,EAAKC,QAAQC,QAAQC,MAAOP,GAE3CQ,EAbc,CAACC,GAAwBC,EAAWD,GAatCE,CAAcR,GAEhC,IAAKK,EACH,MAAM,IAAIN,MACR,yDAAyDC,KAI7D,MAAMS,EAAWC,EAAaV,GAE9BW,EAAcX,EAAcS,EAAS"}