UNPKG

next-intl

Version:

Internationalization (i18n) for Next.js

2 lines (1 loc) 818 B
import{getSortedMessages as e,setNestedProperty as r,isForbiddenObjectKey as s}from"../../utils.js";import{defineCodec as t}from"../ExtractorCodec.js";var o=t((()=>({decode(e){const r=JSON.parse(e),s=[];return n(r,((e,r)=>{s.push({id:r,message:e,references:[],description:[]})})),s},encode(s){const t={};for(const o of e(s))r(t,o.id,o.message);return JSON.stringify(t,null,2)+"\n"},toJSONString:e=>e})));function n(e,r,t=""){for(const o of Object.keys(e)){if(s(o))throw new Error(`Invalid message catalog key: \`${o}\`.`);const a=t?t+"."+o:o,i=e[o];if("string"==typeof i)r(i,a);else{if(Array.isArray(i))throw new Error(`Message at \`${a}\` resolved to an array, but only strings are supported. See https://next-intl.dev/docs/usage/translations#arrays-of-messages`);"object"==typeof i&&n(i,r,a)}}}export{o as default};