next-intl
Version:
Internationalization (i18n) for Next.js
2 lines (1 loc) • 1.23 kB
JavaScript
import e from"path";import{warn as n}from"../plugin/utils.js";function t(n){return e.posix.normalize(n.split(e.win32.sep).join(e.posix.sep))}const o=new Set(["__proto__","constructor","prototype"]);function r(e){return o.has(e)}function c(e){const{locales:n}=e.extract;return"infer"===n||n.length>0}function l(e,n,t){const o=n.split(".");for(const e of o)if(r(e))throw new Error(`Invalid message id segment: ${e}`);let c=e;for(let e=0;e<o.length-1;e++){const n=o[e];Object.prototype.hasOwnProperty.call(c,n)&&"object"==typeof c[n]&&null!==c[n]||(c[n]=Object.create(null)),c=c[n]}c[o[o.length-1]]=t}function s(e){const n=new Set;return e.toSorted(((e,t)=>{const o=e.references[0],r=t.references[0];return null==o&&i(e.id,n),null==r&&i(t.id,n),null==o||null==r?0:f(o,r)}))}function i(e,t){t.has(e)||(t.add(e),n(`Missing file reference for extracted message: ${e}`))}function u(e,n){return e.localeCompare(n,"en")}function f(e,n){const t=u(e.path,n.path);return 0!==t?t:(e.line??0)-(n.line??0)}function p(){return process.cwd()}export{f as compareReferences,p as getDefaultProjectRoot,s as getSortedMessages,c as hasLocalesToExtract,r as isForbiddenObjectKey,u as localeCompare,t as normalizePathToPosix,l as setNestedProperty};