next-intl-split
Version:
A loader for next-intl to split translation files properly.
1 lines • 2.2 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/src/write/index.ts"],"sourcesContent":["import { writeFileSync } from 'fs';\nimport path from 'path';\n\nconst extractLocalesAndMessages = (messages: { [key: string]: any }) =>\n Object.entries(messages);\n\nexport const writeMessages = (\n dictionariesPath: string,\n messages: {},\n options?: {\n muteLogs?: boolean;\n }\n) => {\n const localeMessagesMap = extractLocalesAndMessages(messages);\n\n const isInProduction = process.env.NODE_ENV === 'production';\n\n if (isInProduction && !options?.muteLogs) {\n console.log('\\n');\n console.log(' ▲ Next Intl Split');\n }\n\n for (let index = 0; index < localeMessagesMap.length; index++) {\n const locale = localeMessagesMap[index][0];\n const localeMessages = localeMessagesMap[index][1];\n\n try {\n const pathToWrite = path.resolve(dictionariesPath, `${locale}.json`);\n const content = JSON.stringify(localeMessages, null, 2);\n\n writeFileSync(pathToWrite, content);\n\n if (isInProduction && !options?.muteLogs) {\n console.log(`\\tSuccessfully merged JSON content for ${locale}`);\n }\n } catch (error) {\n console.error(\n 'The following error occured in writer in next-intl-split.',\n error\n );\n }\n }\n\n if (isInProduction) console.log('\\n');\n};\n"],"names":["dictionariesPath","messages","options","localeMessagesMap","Object","entries","extractLocalesAndMessages","isInProduction","process","env","NODE_ENV","muteLogs","console","log","index","length","locale","localeMessages","pathToWrite","path","resolve","content","JSON","stringify","writeFileSync","error"],"mappings":"+MAM6B,CAC3BA,EACAC,EACAC,KAIA,MAAMC,EAV0B,CAACF,GACjCG,OAAOC,QAAQJ,GASWK,CAA0BL,GAE9CM,EAA0C,eAAzBC,QAAQC,IAAIC,SAE/BH,IAAmBL,GAASS,WAC9BC,QAAQC,IAAI,MACZD,QAAQC,IAAI,wBAGd,IAAK,IAAIC,EAAQ,EAAGA,EAAQX,EAAkBY,OAAQD,IAAS,CAC7D,MAAME,EAASb,EAAkBW,GAAO,GAClCG,EAAiBd,EAAkBW,GAAO,GAEhD,IACE,MAAMI,EAAcC,EAAI,QAACC,QAAQpB,EAAkB,GAAGgB,UAChDK,EAAUC,KAAKC,UAAUN,EAAgB,KAAM,GAErDO,gBAAcN,EAAaG,GAEvBd,IAAmBL,GAASS,UAC9BC,QAAQC,IAAI,0CAA0CG,IAEzD,CAAC,MAAOS,GACPb,QAAQa,MACN,4DACAA,EAEH,CACF,CAEGlB,GAAgBK,QAAQC,IAAI,KAAK"}