@intlayer/core 8.4.1 → 8.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/getStorageAttributes.cjs +1 -1
- package/dist/cjs/getStorageAttributes.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +1 -1
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs +1 -1
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +1 -1
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/validatePrefix.cjs +1 -1
- package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
- package/dist/esm/getStorageAttributes.mjs +1 -1
- package/dist/esm/getStorageAttributes.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs +1 -1
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs +1 -1
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/localization/localeMapper.mjs +1 -1
- package/dist/esm/localization/localeMapper.mjs.map +1 -1
- package/dist/esm/localization/validatePrefix.mjs +1 -1
- package/dist/esm/localization/validatePrefix.mjs.map +1 -1
- package/dist/types/getLocaleFromPath-621W32QA.d.ts.map +1 -1
- package/dist/types/getLocalizedUrl-BbqeA3-W.d.ts.map +1 -1
- package/dist/types/getMultilingualUrls-CUxYYfA4.d.ts.map +1 -1
- package/dist/types/getPrefix-X9XKkrZD.d.ts.map +1 -1
- package/dist/types/getStorageAttributes-CIO2xWqQ.d.ts.map +1 -1
- package/dist/types/getTranslation-BG2Wg-af.d.ts.map +1 -1
- package/dist/types/validatePrefix-Dtmg7QLq.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);let e=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);let e=require(`@intlayer/config/defaultValues`);const t=t=>{let{name:n,path:r,expires:i,domain:a,secure:o,sameSite:s,httpOnly:c}=t??{};return{name:n??e.COOKIE_NAME,attributes:{path:r,expires:i,domain:a,secure:o,sameSite:s,httpOnly:c}}},n=t=>{let{name:n}=t??{};return{name:n??e.LOCALE_STORAGE_NAME}},r=t=>{let{name:n}=t??{};return{name:n??e.HEADER_NAME}},i=e=>e.type===`cookie`||`sameSite`in e||`httpOnly`in e||`secure`in e,a=e=>e===`cookie`||e===`localStorage`||e===`sessionStorage`||e===`header`,o=e=>{if(typeof e==`string`){if(!a(e))return{cookies:[],localStorage:[],sessionStorage:[],headers:[]};if(e===`cookie`)return{cookies:[t()]};if(e===`localStorage`)return{localStorage:[n()]};if(e===`sessionStorage`)return{sessionStorage:[n()]};if(e===`header`)return{headers:[r()]}}if(typeof e==`object`&&e){let a=e;if(i(a))return{cookies:[t(a)]};if(`type`in a&&a.type===`localStorage`){let{name:e,...t}=a;return{localStorage:[n({name:e,...t})]}}if(`type`in a&&a.type===`sessionStorage`){let{name:e,...t}=a;return{sessionStorage:[n({name:e,...t})]}}if(`type`in a&&a.type===`header`){let{name:e,...t}=a;return{headers:[r({name:e,...t})]}}let{name:o,...s}=a;return{localStorage:[n({name:o,...s})]}}return{cookies:[],localStorage:[],sessionStorage:[],headers:[]}},s=(e,t)=>({cookies:[...e.cookies,...t.cookies??[]],localStorage:[...e.localStorage,...t.localStorage??[]],sessionStorage:[...e.sessionStorage,...t.sessionStorage??[]],headers:[...e.headers,...t.headers??[]]}),c=e=>{let t={cookies:[],localStorage:[],sessionStorage:[],headers:[]};return e===!1||e===void 0?t:Array.isArray(e)?e.reduce((e,t)=>s(e,o(t)),t):s(t,o(e))};exports.getStorageAttributes=c;
|
|
2
2
|
//# sourceMappingURL=getStorageAttributes.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageAttributes.cjs","names":["
|
|
1
|
+
{"version":3,"file":"getStorageAttributes.cjs","names":["COOKIE_NAME","LOCALE_STORAGE_NAME","HEADER_NAME"],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '@intlayer/config/defaultValues';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n StorageAttributes,\n} from '@intlayer/types/config';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ntype CookieEntry = {\n name: string;\n attributes: Omit<CookiesAttributes, 'type' | 'name'>;\n};\n\ntype WebStorageEntry = {\n name: string;\n};\n\ntype HeaderEntry = {\n name: string;\n};\n\nexport type ProcessedStorageAttributes = {\n cookies: CookieEntry[];\n localStorage: WebStorageEntry[];\n sessionStorage: WebStorageEntry[];\n headers: HeaderEntry[];\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Creates a cookie entry with default values for missing attributes\n */\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n\n return {\n name: name ?? COOKIE_NAME,\n attributes: {\n path,\n expires,\n domain,\n secure,\n sameSite,\n httpOnly,\n },\n };\n};\n\n/**\n * Creates a web storage entry (localStorage or sessionStorage) with default name\n */\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? LOCALE_STORAGE_NAME,\n };\n};\n\n/**\n * Creates a header entry with default name\n */\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? HEADER_NAME,\n };\n};\n\n/**\n * Determines if a storage entry is a cookie based on its properties\n */\nconst isCookieEntry = (entry: any): boolean => {\n return (\n entry.type === 'cookie' ||\n 'sameSite' in entry ||\n 'httpOnly' in entry ||\n 'secure' in entry\n );\n};\n\n/**\n * Determines the storage type from a string literal\n */\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' => {\n return (\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header'\n );\n};\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Processes a single storage entry and returns the appropriate storage attributes\n */\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n // Handle string literals\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n\n if (entry === 'cookie') {\n return { cookies: [createCookieEntry()] };\n }\n\n if (entry === 'localStorage') {\n return { localStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'sessionStorage') {\n return { sessionStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'header') {\n return { headers: [createHeaderEntry()] };\n }\n }\n\n // Handle object entries\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | StorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n\n // Handle localStorage\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle sessionStorage\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { sessionStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle header\n if ('type' in typedEntry && typedEntry.type === 'header') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { headers: [createHeaderEntry({ name, ...rest })] };\n }\n\n // Default to localStorage for ambiguous objects\n const { name, ...rest } = typedEntry as Omit<StorageAttributes, 'type'>;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\n/**\n * Merges multiple partial storage attributes into a single result\n */\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => {\n return {\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [\n ...accumulated.localStorage,\n ...(partial.localStorage ?? []),\n ],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n headers: [...accumulated.headers, ...(partial.headers ?? [])],\n };\n};\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, and sessionStorage\n */\nexport const getStorageAttributes = (\n options: IntlayerConfig['routing']['storage']\n): ProcessedStorageAttributes => {\n const emptyResult: ProcessedStorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n headers: [],\n };\n\n // Storage is disabled\n if (options === false || options === undefined) {\n return emptyResult;\n }\n\n // Handle array of storage entries\n if (Array.isArray(options)) {\n return options.reduce<ProcessedStorageAttributes>((acc, entry) => {\n const partial = processStorageEntry(entry);\n return mergeStorageAttributes(acc, partial);\n }, emptyResult);\n }\n\n // Handle single storage entry\n const partial = processStorageEntry(options);\n\n return mergeStorageAttributes(emptyResult, partial);\n};\n"],"mappings":"mJAkDA,MAAM,EACJ,GACgB,CAChB,GAAM,CAAE,OAAM,OAAM,UAAS,SAAQ,SAAQ,WAAU,YACrD,GAAW,EAAE,CAEf,MAAO,CACL,KAAM,GAAQA,EAAAA,YACd,WAAY,CACV,OACA,UACA,SACA,SACA,WACA,WACD,CACF,EAMG,EACJ,GACoB,CACpB,GAAM,CAAE,QAAS,GAAW,EAAE,CAE9B,MAAO,CACL,KAAM,GAAQC,EAAAA,oBACf,EAMG,EACJ,GACgB,CAChB,GAAM,CAAE,QAAS,GAAW,EAAE,CAE9B,MAAO,CACL,KAAM,GAAQC,EAAAA,YACf,EAMG,EAAiB,GAEnB,EAAM,OAAS,UACf,aAAc,GACd,aAAc,GACd,WAAY,EAOV,EACJ,GAGE,IAAU,UACV,IAAU,gBACV,IAAU,kBACV,IAAU,SAWR,EACJ,GACwC,CAExC,GAAI,OAAO,GAAU,SAAU,CAC7B,GAAI,CAAC,EAAc,EAAM,CACvB,MAAO,CAAE,QAAS,EAAE,CAAE,aAAc,EAAE,CAAE,eAAgB,EAAE,CAAE,QAAS,EAAE,CAAE,CAG3E,GAAI,IAAU,SACZ,MAAO,CAAE,QAAS,CAAC,GAAmB,CAAC,CAAE,CAG3C,GAAI,IAAU,eACZ,MAAO,CAAE,aAAc,CAAC,GAAuB,CAAC,CAAE,CAGpD,GAAI,IAAU,iBACZ,MAAO,CAAE,eAAgB,CAAC,GAAuB,CAAC,CAAE,CAGtD,GAAI,IAAU,SACZ,MAAO,CAAE,QAAS,CAAC,GAAmB,CAAC,CAAE,CAK7C,GAAI,OAAO,GAAU,UAAY,EAAgB,CAC/C,IAAM,EAAa,EAEnB,GAAI,EAAc,EAAW,CAC3B,MAAO,CAAE,QAAS,CAAC,EAAkB,EAAgC,CAAC,CAAE,CAI1E,GAAI,SAAU,GAAc,EAAW,OAAS,eAAgB,CAC9D,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,aAAc,CAAC,EAAsB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAIrE,GAAI,SAAU,GAAc,EAAW,OAAS,iBAAkB,CAChE,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,eAAgB,CAAC,EAAsB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAIvE,GAAI,SAAU,GAAc,EAAW,OAAS,SAAU,CACxD,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,QAAS,CAAC,EAAkB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAI5D,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,aAAc,CAAC,EAAsB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAGrE,MAAO,CAAE,QAAS,EAAE,CAAE,aAAc,EAAE,CAAE,eAAgB,EAAE,CAAE,QAAS,EAAE,CAAE,EAMrE,GACJ,EACA,KAEO,CACL,QAAS,CAAC,GAAG,EAAY,QAAS,GAAI,EAAQ,SAAW,EAAE,CAAE,CAC7D,aAAc,CACZ,GAAG,EAAY,aACf,GAAI,EAAQ,cAAgB,EAAE,CAC/B,CACD,eAAgB,CACd,GAAG,EAAY,eACf,GAAI,EAAQ,gBAAkB,EAAE,CACjC,CACD,QAAS,CAAC,GAAG,EAAY,QAAS,GAAI,EAAQ,SAAW,EAAE,CAAE,CAC9D,EASU,EACX,GAC+B,CAC/B,IAAM,EAA0C,CAC9C,QAAS,EAAE,CACX,aAAc,EAAE,CAChB,eAAgB,EAAE,CAClB,QAAS,EAAE,CACZ,CAkBD,OAfI,IAAY,IAAS,IAAY,IAAA,GAC5B,EAIL,MAAM,QAAQ,EAAQ,CACjB,EAAQ,QAAoC,EAAK,IAE/C,EAAuB,EADd,EAAoB,EAAM,CACC,CAC1C,EAAY,CAMV,EAAuB,EAFd,EAAoB,EAAQ,CAEO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslation.cjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"getTranslation.cjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely processed.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n\n // Don't process Promises (e.g., Next.js 15+ params)\n if (value instanceof Promise || typeof (value as any).then === 'function') {\n return false;\n }\n\n // Don't process React elements or other framework VNodes\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n\n // Only process plain objects and arrays\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects.\n * Resembles the behavior of `defu` but respects `isPlainObject` to avoid merging React elements.\n * Arrays are replaced, not merged.\n */\nconst deepMergeObjects = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n\n if (Array.isArray(target)) return target;\n\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n for (const key of Object.keys(source)) {\n if (key === '__proto__' || key === 'constructor') continue;\n\n if (Object.hasOwn(target, key)) {\n result[key] = deepMergeObjects(target[key], source[key]);\n } else {\n result[key] = source[key];\n }\n }\n return result;\n }\n\n return target;\n};\n\n/**\n * Recursively removes undefined values from an object.\n * Handles circular references by tracking visited objects.\n */\nconst removeUndefinedValues = <T>(\n object: T,\n visited = new WeakSet<object>()\n): T => {\n if (typeof object !== 'object' || object === null) {\n return object;\n }\n\n // Handle circular references - return original to avoid infinite recursion\n if (visited.has(object)) {\n return object;\n }\n visited.add(object);\n\n // Don't process non-plain objects (Promises, React elements, etc.)\n if (!isPlainObject(object)) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map((item) => removeUndefinedValues(item, visited)) as T;\n }\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(object)) {\n if (value !== undefined) {\n result[key] = removeUndefinedValues(value, visited);\n }\n }\n return result as T;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const results: Content[] = [];\n\n const getContent = (loc: string) =>\n languageContent[loc as keyof typeof languageContent];\n\n // Get Target Content\n const content = getContent(locale);\n if (typeof content === 'string') {\n return content;\n } else if (content !== undefined) {\n results.push(content);\n }\n\n // Get Target Generic Content (e.g. 'en' from 'en-US')\n if (locale.includes('-')) {\n const genericLocale = locale.split('-')[0];\n if (genericLocale in languageContent) {\n const genericContent = getContent(genericLocale);\n\n if (typeof genericContent === 'string') {\n // If we haven't found specific content yet, return generic string\n if (results.length === 0) return genericContent;\n } else if (genericContent !== undefined) {\n results.push(genericContent);\n }\n }\n }\n\n // Get Fallback Content\n if (fallback !== undefined && fallback !== locale) {\n // 3a. Fallback Specific\n if (fallback in languageContent) {\n const fallbackContent = getContent(fallback);\n\n if (typeof fallbackContent === 'string') {\n if (results.length === 0) return fallbackContent;\n } else if (fallbackContent !== undefined) {\n results.push(fallbackContent);\n }\n }\n\n // Fallback Generic (The missing piece: e.g. 'en' from 'en-GB' fallback)\n if (fallback.includes('-')) {\n const genericFallback = fallback.split('-')[0];\n const genericLocale = locale.split('-')[0];\n\n // Only add if it's different from the target generic (to avoid duplication)\n // and exists in the dictionary\n if (\n genericFallback !== genericLocale &&\n genericFallback in languageContent\n ) {\n const genericFallbackContent = getContent(genericFallback);\n\n if (typeof genericFallbackContent === 'string') {\n if (results.length === 0) return genericFallbackContent;\n } else if (genericFallbackContent !== undefined) {\n results.push(genericFallbackContent);\n }\n }\n }\n }\n\n if (results.length === 0) {\n return undefined as Content;\n }\n\n // Clean undefined values so they don't overwrite fallbacks\n // Order: [Target, Generic, Fallback, FallbackGeneric]\n // defu first argument takes precedence, so Target wins\n const cleanResults = results\n .filter((item) => typeof item !== 'undefined')\n .map((item) => removeUndefinedValues(item));\n\n // If only one result, return it directly (no merging needed)\n if (cleanResults.length === 1) {\n return cleanResults[0];\n }\n\n // If the first result is an array, return it directly (arrays replace, don't merge)\n // defu would incorrectly convert arrays to objects with numeric keys\n if (Array.isArray(cleanResults[0])) {\n return cleanResults[0];\n }\n\n // Merge objects with custom merge - first argument takes precedence\n // Cast to object[] since by this point we've already returned early for strings, arrays, and single results\n return (cleanResults as object[]).reduce((acc, curr) =>\n deepMergeObjects(acc, curr)\n ) as Content;\n};\n"],"mappings":"mEASA,MAAM,EAAiB,GAA4B,CAWjD,GAVsB,OAAO,GAAU,WAAnC,GAKA,aAAiB,SAAW,OAAQ,EAAc,MAAS,YAM5D,EAAc,WAAa,IAAA,IAC3B,EAAc,cAAgB,IAAA,IAC9B,EAAc,WAAa,IAAA,IAC3B,EAAc,QAAU,IAAA,GAEzB,MAAO,GAIT,IAAM,EAAQ,OAAO,eAAe,EAAM,CAC1C,OAAO,IAAU,OAAO,WAAa,IAAU,MAAQ,MAAM,QAAQ,EAAM,EAQvE,GAAoB,EAAa,IAAqB,CAC1D,GAAI,IAAW,IAAA,GAAW,OAAO,EAGjC,GAFI,IAAW,IAAA,IAEX,MAAM,QAAQ,EAAO,CAAE,OAAO,EAElC,GAAI,EAAc,EAAO,EAAI,EAAc,EAAO,CAAE,CAClD,IAAM,EAAS,CAAE,GAAG,EAAQ,CAC5B,IAAK,IAAM,KAAO,OAAO,KAAK,EAAO,CAC/B,IAAQ,aAAe,IAAQ,gBAE/B,OAAO,OAAO,EAAQ,EAAI,CAC5B,EAAO,GAAO,EAAiB,EAAO,GAAM,EAAO,GAAK,CAExD,EAAO,GAAO,EAAO,IAGzB,OAAO,EAGT,OAAO,GAOH,GACJ,EACA,EAAU,IAAI,UACR,CAYN,GAXI,OAAO,GAAW,WAAY,GAK9B,EAAQ,IAAI,EAAO,GAGvB,EAAQ,IAAI,EAAO,CAGf,CAAC,EAAc,EAAO,EACxB,OAAO,EAGT,GAAI,MAAM,QAAQ,EAAO,CACvB,OAAO,EAAO,IAAK,GAAS,EAAsB,EAAM,EAAQ,CAAC,CAGnE,IAAM,EAAkC,EAAE,CAC1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAO,CAC3C,IAAU,IAAA,KACZ,EAAO,GAAO,EAAsB,EAAO,EAAQ,EAGvD,OAAO,GA0BI,GACX,EACA,EACA,IACY,CACZ,IAAM,EAAqB,EAAE,CAEvB,EAAc,GAClB,EAAgB,GAGZ,EAAU,EAAW,EAAO,CAClC,GAAI,OAAO,GAAY,SACrB,OAAO,EAMT,GALW,IAAY,IAAA,IACrB,EAAQ,KAAK,EAAQ,CAInB,EAAO,SAAS,IAAI,CAAE,CACxB,IAAM,EAAgB,EAAO,MAAM,IAAI,CAAC,GACxC,GAAI,KAAiB,EAAiB,CACpC,IAAM,EAAiB,EAAW,EAAc,CAEhD,GAAI,OAAO,GAAmB,aAExB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAmB,IAAA,IAC5B,EAAQ,KAAK,EAAe,EAMlC,GAAI,IAAa,IAAA,IAAa,IAAa,EAAQ,CAEjD,GAAI,KAAY,EAAiB,CAC/B,IAAM,EAAkB,EAAW,EAAS,CAE5C,GAAI,OAAO,GAAoB,aACzB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAoB,IAAA,IAC7B,EAAQ,KAAK,EAAgB,CAKjC,GAAI,EAAS,SAAS,IAAI,CAAE,CAC1B,IAAM,EAAkB,EAAS,MAAM,IAAI,CAAC,GAK5C,GACE,IALoB,EAAO,MAAM,IAAI,CAAC,IAMtC,KAAmB,EACnB,CACA,IAAM,EAAyB,EAAW,EAAgB,CAE1D,GAAI,OAAO,GAA2B,aAChC,EAAQ,SAAW,EAAG,OAAO,OACxB,IAA2B,IAAA,IACpC,EAAQ,KAAK,EAAuB,GAM5C,GAAI,EAAQ,SAAW,EACrB,OAMF,IAAM,EAAe,EAClB,OAAQ,GAAgB,IAAS,OAAY,CAC7C,IAAK,GAAS,EAAsB,EAAK,CAAC,CAe7C,OAZI,EAAa,SAAW,GAMxB,MAAM,QAAQ,EAAa,GAAG,CACzB,EAAa,GAKd,EAA0B,QAAQ,EAAK,IAC7C,EAAiB,EAAK,EAAK,CAC5B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/localeStorage.cjs`),n=require(`./localeResolver.cjs`),r=require(`./localeDetector.cjs`);let i=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/localeStorage.cjs`),n=require(`./localeResolver.cjs`),r=require(`./localeDetector.cjs`);let i=require(`@intlayer/config/defaultValues`),a=require(`@intlayer/config/built`);a=e.t(a);const o=async(e={})=>{let o=a.default?.internationalization?.defaultLocale??i.DEFAULT_LOCALE,s=a.default?.internationalization?.locales??i.LOCALES,c=t.getLocaleFromStorage({getCookie:e.getCookie,getHeader:e.getHeader});if(c)return c;let l=e.getHeader?.(`accept-language`);return l&&n.localeResolver(r.getPreferredLanguages(l,s),s,o)||o};exports.getLocale=o;
|
|
2
2
|
//# sourceMappingURL=getLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.cjs","names":["configuration","
|
|
1
|
+
{"version":3,"file":"getLocale.cjs","names":["configuration","DEFAULT_LOCALE","LOCALES","getLocaleFromStorage","localeResolver","getPreferredLanguages"],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DEFAULT_LOCALE, LOCALES } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getLocaleFromStorage } from '../utils/localeStorage';\nimport { getPreferredLanguages } from './localeDetector';\nimport { localeResolver } from './localeResolver';\n\nexport type RequestContext = {\n getHeader?: (name: string) => string | null | undefined;\n getCookie?: (name: string) => string | null | undefined;\n};\n\nexport const getLocale = async (ctx: RequestContext = {}): Promise<Locale> => {\n const defaultLocale =\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE;\n const availableLocales =\n configuration?.internationalization?.locales ?? LOCALES;\n\n // Try locale from storage (cookie or header)\n const storedLocale = getLocaleFromStorage({\n getCookie: ctx.getCookie,\n getHeader: ctx.getHeader,\n });\n\n if (storedLocale) {\n return storedLocale;\n }\n\n // Fallback to Accept-Language negotiation\n const acceptLanguageHeader = ctx.getHeader?.('accept-language');\n\n if (!acceptLanguageHeader) {\n return defaultLocale;\n }\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales\n );\n\n const userFallbackLocale = localeResolver(\n preferredLocaleStrings,\n availableLocales,\n defaultLocale\n );\n\n if (userFallbackLocale) {\n return userFallbackLocale;\n }\n\n // Default locale\n return defaultLocale;\n};\n"],"mappings":"qTAYA,MAAa,EAAY,MAAO,EAAsB,EAAE,GAAsB,CAC5E,IAAM,EACJA,EAAAA,SAAe,sBAAsB,eAAiBC,EAAAA,eAClD,EACJD,EAAAA,SAAe,sBAAsB,SAAWE,EAAAA,QAG5C,EAAeC,EAAAA,qBAAqB,CACxC,UAAW,EAAI,UACf,UAAW,EAAI,UAChB,CAAC,CAEF,GAAI,EACF,OAAO,EAIT,IAAM,EAAuB,EAAI,YAAY,kBAAkB,CAsB/D,OApBK,GASsBC,EAAAA,eALIC,EAAAA,sBAC7B,EACA,EACD,CAIC,EACA,EACD,EAZQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/checkIsURLAbsolute.cjs`);let n=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/checkIsURLAbsolute.cjs`);let n=require(`@intlayer/config/defaultValues`),r=require(`@intlayer/config/built`);r=e.t(r);const i=(e=`/`,i)=>{let{defaultLocale:a,locales:o,mode:s}={defaultLocale:r.default?.internationalization?.defaultLocale??n.DEFAULT_LOCALE,mode:r.default?.routing?.mode??n.ROUTING_MODE,locales:r.default?.internationalization?.locales??n.LOCALES,...i};if(!a||!o)return n.DEFAULT_LOCALE;let c=t.checkIsURLAbsolute(e),l=e;e?.endsWith(`/`)&&e.length>1&&(l=e.slice(0,-1));let u=c?new URL(l):new URL(l,`http://example.com`);if(s===`search-params`){let e=u.searchParams.get(`locale`);return e&&o.includes(e)?e:a}if(s===`no-prefix`)return a;let d=u.pathname.split(`/`)[1];if(d&&o.includes(d))return d;if(s===`prefix-no-default`)return a};exports.getLocaleFromPath=i;
|
|
2
2
|
//# sourceMappingURL=getLocaleFromPath.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromPath.cjs","names":["configuration","
|
|
1
|
+
{"version":3,"file":"getLocaleFromPath.cjs","names":["configuration","DEFAULT_LOCALE","ROUTING_MODE","LOCALES","checkIsURLAbsolute"],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\ntype GetLocaleFromPathOptions = {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n};\n\n/**\n * Extracts the locale segment from the given URL or pathname based on the routing mode.\n *\n * Mode Behaviors:\n * - 'prefix-no-default': Checks path prefiIf no prefix found, assumes default locale.\n * - 'prefix-all': Checks path prefix.\n * - 'search-params': Checks for 'locale' query parameter.\n * - 'no-prefix': Returns undefined (or default if fallback is true).\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @returns The detected locale, default locale (if fallback/implicit), or undefined.\n */\nexport const getLocaleFromPath = (\n inputUrl: string = '/',\n options?: GetLocaleFromPathOptions\n): Locale | undefined => {\n const { defaultLocale, locales, mode } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n ...options,\n };\n\n if (!defaultLocale || !locales) {\n return DEFAULT_LOCALE;\n }\n\n // Prepare the URL object\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n let fixedInputUrl = inputUrl;\n\n if (inputUrl?.endsWith('/') && inputUrl.length > 1) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n // Handle 'search-params' mode\n // Example: /dashboard?locale=fr\n if (mode === 'search-params') {\n const localeParam = url.searchParams.get('locale');\n\n if (localeParam && locales.includes(localeParam)) {\n return localeParam as Locale;\n }\n\n return defaultLocale as Locale;\n }\n\n // Handle 'no-prefix' mode\n // The locale is not stored in the URL path.\n if (mode === 'no-prefix') {\n return defaultLocale as Locale;\n }\n\n // Handle Prefix Modes ('prefix-all' | 'prefix-no-default')\n const pathname = url.pathname;\n\n // Split the pathname to extract the first segment\n // pathSegments[0] is empty string because path starts with /\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1];\n\n // Check if the first segment is a valid supported locale\n const isSegmentLocale = firstSegment && locales.includes(firstSegment);\n\n if (isSegmentLocale) {\n return firstSegment as Locale;\n }\n\n // If the first segment is NOT a locale (e./dashboard), handle based on mode\n if (mode === 'prefix-no-default') {\n // In this mode, absence of a prefix implies the default locale\n return defaultLocale as Locale;\n }\n\n return undefined;\n};\n"],"mappings":"sPA6BA,MAAa,GACX,EAAmB,IACnB,IACuB,CACvB,GAAM,CAAE,gBAAe,UAAS,QAAS,CACvC,cACEA,EAAAA,SAAe,sBAAsB,eAAiBC,EAAAA,eACxD,KAAMD,EAAAA,SAAe,SAAS,MAAQE,EAAAA,aACtC,QAASF,EAAAA,SAAe,sBAAsB,SAAWG,EAAAA,QACzD,GAAG,EACJ,CAED,GAAI,CAAC,GAAiB,CAAC,EACrB,OAAOF,EAAAA,eAIT,IAAM,EAAgBG,EAAAA,mBAAmB,EAAS,CAC9C,EAAgB,EAEhB,GAAU,SAAS,IAAI,EAAI,EAAS,OAAS,IAC/C,EAAgB,EAAS,MAAM,EAAG,GAAG,EAIvC,IAAM,EAAM,EACR,IAAI,IAAI,EAAc,CACtB,IAAI,IAAI,EAAe,qBAAqB,CAIhD,GAAI,IAAS,gBAAiB,CAC5B,IAAM,EAAc,EAAI,aAAa,IAAI,SAAS,CAMlD,OAJI,GAAe,EAAQ,SAAS,EAAY,CACvC,EAGF,EAKT,GAAI,IAAS,YACX,OAAO,EAST,IAAM,EALW,EAAI,SAIS,MAAM,IAAI,CACN,GAKlC,GAFwB,GAAgB,EAAQ,SAAS,EAAa,CAGpE,OAAO,EAIT,GAAI,IAAS,oBAEX,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/checkIsURLAbsolute.cjs`),n=require(`./getPathWithoutLocale.cjs`),r=require(`./getPrefix.cjs`),i=require(`./rewriteUtils.cjs`);let a=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/checkIsURLAbsolute.cjs`),n=require(`./getPathWithoutLocale.cjs`),r=require(`./getPrefix.cjs`),i=require(`./rewriteUtils.cjs`);let a=require(`@intlayer/config/defaultValues`),o=require(`@intlayer/config/built`);o=e.t(o);const s=(e,s=o.default?.internationalization?.defaultLocale,c={})=>{let{defaultLocale:l,mode:u,locales:d,rewrite:f}={defaultLocale:o.default?.internationalization?.defaultLocale??a.DEFAULT_LOCALE,mode:o.default?.routing?.mode??a.ROUTING_MODE,locales:o.default?.internationalization?.locales??a.LOCALES,rewrite:o.default?.routing?.rewrite,...c},p=n.getPathWithoutLocale(e,d),m=i.getRewriteRules(f,`url`);if(u===`no-prefix`)return i.getLocalizedPath(i.getCanonicalPath(p,void 0,m),s,m).path;let h=t.checkIsURLAbsolute(p),g=h?new URL(p):new URL(p,`http://example.com`),_=h?`${g.protocol}//${g.host}`:``,v=i.getLocalizedPath(i.getCanonicalPath(g.pathname,void 0,m),s,m).path;if(u===`search-params`){let e=new URLSearchParams(g.search);e.set(`locale`,s.toString());let t=e.toString(),n=t?`${v}?${t}`:v;return h?`${_}${n}${g.hash}`:`${n}${g.hash}`}let{prefix:y}=r.getPrefix(s,{defaultLocale:l,mode:u,locales:d}),b=`/${y}${v}`;return b=b.replaceAll(/\/+/g,`/`),b.length>1&&b.endsWith(`/`)&&(b=b.slice(0,-1)),h?`${_}${b}${g.search}${g.hash}`:`${b}${g.search}${g.hash}`};exports.getLocalizedUrl=s;
|
|
2
2
|
//# sourceMappingURL=getLocalizedUrl.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedUrl.cjs","names":["configuration","
|
|
1
|
+
{"version":3,"file":"getLocalizedUrl.cjs","names":["configuration","DEFAULT_LOCALE","ROUTING_MODE","LOCALES","getPathWithoutLocale","getRewriteRules","getLocalizedPath","getCanonicalPath","checkIsURLAbsolute","getPrefix"],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\nimport { getPrefix } from './getPrefix';\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\n} from './rewriteUtils';\n\n/**\n * Generate URL by prefixing the given URL with the referenced locale or adding search parameters\n * based on the routing mode. Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-no-default' });\n * // Returns '/fr/about' for the French locale\n * // Returns '/about' for the English locale (default)\n *\n * // prefix-all mode\n * getLocalizedUrl('/about', 'en', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-all' });\n * // Returns '/en/about' for the English locale\n * // Returns '/fr/about' for the French locale\n *\n * // search-params mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'search-params' });\n * // Returns '/about?locale=fr' for the French locale\n *\n * // no-prefix mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'no-prefix' });\n * // Returns '/about' for any locale\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param currentLocale - The current locale.\n * @param options - Configuration options\n * @param options.locales - Optional array of supported locales. Defaults to configured locales.\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns The localized URL for the current locale.\n */\nexport const getLocalizedUrl = (\n url: string,\n currentLocale: LocalesValues = configuration?.internationalization\n ?.defaultLocale,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n } = {}\n): string => {\n const { defaultLocale, mode, locales, rewrite } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n rewrite: configuration?.routing?.rewrite,\n ...options,\n };\n\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n const urlRewriteRules = getRewriteRules(rewrite, 'url');\n\n if (mode === 'no-prefix') {\n // Resolve to canonical path first from the potentially localized input URL\n const canonicalPathname = getCanonicalPath(\n urlWithoutLocale,\n undefined,\n urlRewriteRules\n );\n\n // Localize the canonical path for the target locale\n return getLocalizedPath(\n canonicalPathname,\n currentLocale as Locale,\n urlRewriteRules\n ).path;\n }\n\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Resolve to canonical path first\n const canonicalPathname = getCanonicalPath(\n parsedUrl.pathname,\n undefined,\n urlRewriteRules\n );\n\n // Localize the canonical path for the target locale\n const translatedPathname = getLocalizedPath(\n canonicalPathname,\n currentLocale as Locale,\n urlRewriteRules\n ).path;\n\n if (mode === 'search-params') {\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', currentLocale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${translatedPathname}?${queryString}`\n : translatedPathname;\n\n return isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n }\n\n const { prefix } = getPrefix(currentLocale, {\n defaultLocale,\n mode,\n locales,\n });\n\n let localizedPath = `/${prefix}${translatedPathname}`;\n\n localizedPath = localizedPath.replaceAll(/\\/+/g, '/');\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n const finalUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n\n return finalUrl;\n};\n"],"mappings":"2VAsDA,MAAa,GACX,EACA,EAA+BA,EAAAA,SAAe,sBAC1C,cACJ,EAKI,EAAE,GACK,CACX,GAAM,CAAE,gBAAe,OAAM,UAAS,WAAY,CAChD,cACEA,EAAAA,SAAe,sBAAsB,eAAiBC,EAAAA,eACxD,KAAMD,EAAAA,SAAe,SAAS,MAAQE,EAAAA,aACtC,QAASF,EAAAA,SAAe,sBAAsB,SAAWG,EAAAA,QACzD,QAASH,EAAAA,SAAe,SAAS,QACjC,GAAG,EACJ,CAEK,EAAmBI,EAAAA,qBAAqB,EAAK,EAAQ,CAErD,EAAkBC,EAAAA,gBAAgB,EAAS,MAAM,CAEvD,GAAI,IAAS,YASX,OAAOC,EAAAA,iBAPmBC,EAAAA,iBACxB,EACA,IAAA,GACA,EACD,CAKC,EACA,EACD,CAAC,KAGJ,IAAM,EAAgBC,EAAAA,mBAAmB,EAAiB,CAEpD,EAAY,EACd,IAAI,IAAI,EAAiB,CACzB,IAAI,IAAI,EAAkB,qBAAqB,CAE7C,EAAU,EACZ,GAAG,EAAU,SAAS,IAAI,EAAU,OACpC,GAUE,EAAqBF,EAAAA,iBAPDC,EAAAA,iBACxB,EAAU,SACV,IAAA,GACA,EACD,CAKC,EACA,EACD,CAAC,KAEF,GAAI,IAAS,gBAAiB,CAC5B,IAAM,EAAe,IAAI,gBAAgB,EAAU,OAAO,CAC1D,EAAa,IAAI,SAAU,EAAc,UAAU,CAAC,CAEpD,IAAM,EAAc,EAAa,UAAU,CACrC,EAAgB,EAClB,GAAG,EAAmB,GAAG,IACzB,EAEJ,OAAO,EACH,GAAG,IAAU,IAAgB,EAAU,OACvC,GAAG,IAAgB,EAAU,OAGnC,GAAM,CAAE,UAAWE,EAAAA,UAAU,EAAe,CAC1C,gBACA,OACA,UACD,CAAC,CAEE,EAAgB,IAAI,IAAS,IAYjC,MAVA,GAAgB,EAAc,WAAW,OAAQ,IAAI,CAEjD,EAAc,OAAS,GAAK,EAAc,SAAS,IAAI,GACzD,EAAgB,EAAc,MAAM,EAAG,GAAG,EAG3B,EACb,GAAG,IAAU,IAAgB,EAAU,SAAS,EAAU,OAC1D,GAAG,IAAgB,EAAU,SAAS,EAAU"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./getLocalizedUrl.cjs`);let n=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./getLocalizedUrl.cjs`);let n=require(`@intlayer/config/defaultValues`),r=require(`@intlayer/config/built`);r=e.t(r);const i=(e,i={})=>{let{defaultLocale:a,mode:o,locales:s,rewrite:c}={defaultLocale:r.default?.internationalization?.defaultLocale??n.DEFAULT_LOCALE,mode:r.default?.routing?.mode??n.ROUTING_MODE,locales:r.default?.internationalization?.locales??n.LOCALES,rewrite:r.default?.routing?.rewrite,...i};return(s??[]).reduce((n,r)=>(n[r]=t.getLocalizedUrl(e,r,{locales:s,defaultLocale:a,mode:o,rewrite:c}),n),{})};exports.getMultilingualUrls=i;
|
|
2
2
|
//# sourceMappingURL=getMultilingualUrls.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualUrls.cjs","names":["configuration","
|
|
1
|
+
{"version":3,"file":"getMultilingualUrls.cjs","names":["configuration","DEFAULT_LOCALE","ROUTING_MODE","LOCALES","getLocalizedUrl"],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getLocalizedUrl } from './getLocalizedUrl';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'search-params' })\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param options - Configuration options\n * @param options.locales - Optional array of supported locales. Defaults to configured locales.\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n } = {}\n): StrictModeLocaleMap<string> => {\n const { defaultLocale, mode, locales, rewrite } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n rewrite: configuration?.routing?.rewrite,\n ...options,\n };\n\n // Generate multilingual URLs by iterating over each locale and calling getLocalizedUrl\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Get the localized URL for this locale\n const localizedUrl = getLocalizedUrl(url, locale, {\n locales,\n defaultLocale,\n mode,\n rewrite,\n });\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":"4OA+CA,MAAa,GACX,EACA,EAKI,EAAE,GAC0B,CAChC,GAAM,CAAE,gBAAe,OAAM,UAAS,WAAY,CAChD,cACEA,EAAAA,SAAe,sBAAsB,eAAiBC,EAAAA,eACxD,KAAMD,EAAAA,SAAe,SAAS,MAAQE,EAAAA,aACtC,QAASF,EAAAA,SAAe,sBAAsB,SAAWG,EAAAA,QACzD,QAASH,EAAAA,SAAe,SAAS,QACjC,GAAG,EACJ,CAqBD,OAlB0B,GAAW,EAAE,EAAE,QACtC,EAAK,KAUJ,EAAI,GARiBI,EAAAA,gBAAgB,EAAK,EAAQ,CAChD,UACA,gBACA,OACA,UACD,CAAC,CAKK,GAET,EAAE,CACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`@intlayer/config/defaultValues`),n=require(`@intlayer/config/built`);n=e.t(n);const r=(e,r={})=>{let{defaultLocale:i,mode:a,locales:o}={defaultLocale:n.default?.internationalization?.defaultLocale??t.DEFAULT_LOCALE,mode:n.default?.routing?.mode??t.ROUTING_MODE,locales:n.default?.internationalization?.locales??t.LOCALES,...r};return!e||!o.includes(e)?{prefix:``,localePrefix:void 0}:a===`prefix-all`||a===`prefix-no-default`&&i!==e?{prefix:`${e}/`,localePrefix:e}:{prefix:``,localePrefix:void 0}};exports.getPrefix=r;
|
|
2
2
|
//# sourceMappingURL=getPrefix.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrefix.cjs","names":["configuration","
|
|
1
|
+
{"version":3,"file":"getPrefix.cjs","names":["configuration","DEFAULT_LOCALE","ROUTING_MODE","LOCALES"],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type GetPrefixOptions = {\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n};\n\nexport type GetPrefixResult = {\n /**\n * The complete base URL path with leading and trailing slashes.\n *\n * @example\n * // https://example.com/fr/about -> '/fr'\n * // https://example.com/about -> ''\n */\n prefix: string;\n /**\n * The locale identifier without slashes.\n *\n * @example\n * // https://example.com/fr/about -> 'fr'\n * // https://example.com/about -> undefined\n */\n localePrefix: Locale | undefined;\n};\n\n/**\n * Determines the URL prefix for a given locale based on the routing mode configuration.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode with default locale\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // prefix-no-default mode with non-default locale\n * getPrefix('fr', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '/fr', localePrefix: 'fr' }\n *\n * // prefix-all mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { prefix: '/en', localePrefix: locale }\n *\n * // search-params mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'search-params' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // no-prefix mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { prefix: '', localePrefix: undefined }\n * ```\n *\n * @param locale - The locale to check for prefix. If not provided, uses configured default locale.\n * @param options - Configuration options\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object containing pathPrefix, prefix, and localePrefix for the given locale.\n */\nexport const getPrefix = (\n locale: LocalesValues | undefined,\n options: {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n } = {}\n): GetPrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n ...options,\n };\n\n if (!locale || !locales.includes(locale)) {\n return {\n prefix: '',\n localePrefix: undefined,\n };\n }\n\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n mode === 'prefix-all' ||\n (mode === 'prefix-no-default' && defaultLocale !== locale);\n\n if (shouldPrefix) {\n return {\n prefix: `${locale}/`,\n localePrefix: locale as Locale,\n };\n }\n\n return {\n prefix: '',\n localePrefix: undefined,\n };\n};\n"],"mappings":"yMAmEA,MAAa,GACX,EACA,EAII,EAAE,GACc,CACpB,GAAM,CAAE,gBAAe,OAAM,WAAY,CACvC,cACEA,EAAAA,SAAe,sBAAsB,eAAiBC,EAAAA,eACxD,KAAMD,EAAAA,SAAe,SAAS,MAAQE,EAAAA,aACtC,QAASF,EAAAA,SAAe,sBAAsB,SAAWG,EAAAA,QACzD,GAAG,EACJ,CAqBD,MAnBI,CAAC,GAAU,CAAC,EAAQ,SAAS,EAAO,CAC/B,CACL,OAAQ,GACR,aAAc,IAAA,GACf,CAKD,IAAS,cACR,IAAS,qBAAuB,IAAkB,EAG5C,CACL,OAAQ,GAAG,EAAO,GAClB,aAAc,EACf,CAGI,CACL,OAAQ,GACR,aAAc,IAAA,GACf"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`@intlayer/config/defaultValues`),n=require(`@intlayer/config/built`);n=e.t(n);const r=(e,t,n)=>n===`no-prefix`||n===`search-params`?!1:n===`prefix-all`?!0:e!==t,i=(e,i=n.default?.internationalization.locales??[],a=n.default?.internationalization.defaultLocale??t.DEFAULT_LOCALE,o=n.default?.routing?.mode??`prefix-no-default`)=>(i??[]).map(t=>e({locale:t,defaultLocale:a,locales:i,isDefault:t===a,urlPrefix:r(t,a,o)?`/${t}`:``})),a=(e,i=n.default?.internationalization.locales??[],a=n.default?.internationalization.defaultLocale??t.DEFAULT_LOCALE,o=n.default?.routing?.mode??`prefix-no-default`)=>i.flatMap(t=>e({locale:t,defaultLocale:a,locales:i,isDefault:t===a,urlPrefix:r(t,a,o)?`/${t}`:``})),o=(e,i=n.default?.internationalization.locales??[],a=n.default?.internationalization.defaultLocale??t.DEFAULT_LOCALE,o=n.default?.routing?.mode??`prefix-no-default`)=>(i??[]).reduce((t,n)=>(t[n]=e({locale:n,defaultLocale:a,locales:i,isDefault:n===a,urlPrefix:r(n,a,o)?`/${n}`:``}),t),{});exports.localeFlatMap=a,exports.localeMap=i,exports.localeRecord=o;
|
|
2
2
|
//# sourceMappingURL=localeMapper.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeMapper.cjs","names":["configuration","
|
|
1
|
+
{"version":3,"file":"localeMapper.cjs","names":["configuration","DEFAULT_LOCALE"],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type LocaleData = {\n locale: Locale;\n defaultLocale: Locale;\n isDefault: boolean;\n locales: Locale[];\n urlPrefix: string;\n};\n\n/**\n * Determine if the locale should be prefixed in the URL based on routing mode\n */\nconst shouldPrefixLocale = (\n locale: LocalesValues,\n defaultLocale: LocalesValues,\n mode: 'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params'\n): boolean => {\n if (mode === 'no-prefix' || mode === 'search-params') {\n return false;\n }\n if (mode === 'prefix-all') {\n return true;\n }\n // 'prefix-no-default'\n return locale !== defaultLocale;\n};\n\n/**\n * Map the locale data to an array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * ({\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }),\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an object\n * @returns An array of objects\n */\nexport const localeMap = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n (locales ?? []).map((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' ,\n * path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' ,\n * path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' ,\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(\n mapper: (locale: LocaleData) => T[],\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n locales.flatMap((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Creates a record object mapping locales to values transformed by the mapper function\n *\n * @example\n * ```ts\n * const translations = localeRecord(({ locale }) =>\n * require(`./translations/${locale}.json`)\n * );\n *\n * // Result\n *\n * en: ... , // Content of translations/en.json\n * fr: ... , // Content of translations/fr.json\n * es: ...\n *\n * ```\n *\n * @param mapper - Function that takes locale data and returns a value for that locale\n * @param locales - Array of locale codes to map over (defaults to configured locales)\n * @param defaultLocale - The default locale (defaults to configured default)\n * @param mode - URL routing mode for locale handling (defaults to configured value)\n * @returns Record mapping locale codes to mapped values\n */\nexport const localeRecord = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): Record<LocalesValues, T> =>\n (locales ?? []).reduce(\n (acc, locale) => {\n acc[locale] = mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData);\n return acc;\n },\n {} as Record<LocalesValues, T>\n );\n"],"mappings":"yMAgBA,MAAM,GACJ,EACA,EACA,IAEI,IAAS,aAAe,IAAS,gBAC5B,GAEL,IAAS,aACJ,GAGF,IAAW,EA6BP,GACX,EACA,EAA2BA,EAAAA,SAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+BA,EAAAA,SAAe,qBAC3C,eAAiBC,EAAAA,eACpB,EAIsBD,EAAAA,SAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,IAAK,GACnB,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CA4BU,GACX,EACA,EAA2BA,EAAAA,SAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+BA,EAAAA,SAAe,qBAC3C,eAAiBC,EAAAA,eACpB,EAIsBD,EAAAA,SAAe,SAAS,MAAQ,sBAEtD,EAAQ,QAAS,GACf,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CAyBU,GACX,EACA,EAA2BA,EAAAA,SAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+BA,EAAAA,SAAe,qBAC3C,eAAiBC,EAAAA,eACpB,EAIsBD,EAAAA,SAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,QACb,EAAK,KACJ,EAAI,GAAU,EAAO,CACnB,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACT,GAET,EAAE,CACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./getPrefix.cjs`);let n=require(`@intlayer/config/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./getPrefix.cjs`);let n=require(`@intlayer/config/defaultValues`),r=require(`@intlayer/config/built`);r=e.t(r);const i=(e,i)=>{let{defaultLocale:a,mode:o,locales:s}={defaultLocale:r.default?.internationalization?.defaultLocale??n.DEFAULT_LOCALE,mode:r.default?.routing?.mode??n.ROUTING_MODE,locales:r.default?.internationalization?.locales??n.LOCALES,...i},{localePrefix:c}=t.getPrefix(e||a,{mode:o,locales:s,defaultLocale:a});return c===e&&e===void 0?{isValid:!0,localePrefix:void 0}:{isValid:s.some(t=>t===e),localePrefix:c}};exports.validatePrefix=i;
|
|
2
2
|
//# sourceMappingURL=validatePrefix.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatePrefix.cjs","names":["configuration","
|
|
1
|
+
{"version":3,"file":"validatePrefix.cjs","names":["configuration","DEFAULT_LOCALE","ROUTING_MODE","LOCALES","getPrefix"],"sources":["../../../src/localization/validatePrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getPrefix } from './getPrefix';\n\nexport type ValidatePrefixResult = {\n isValid: boolean;\n localePrefix: string | undefined;\n};\n\n/**\n * Checks whether a given locale is valid based on the configured locales.\n *\n * @param locale - The locale value to validate. Can be `undefined` or `null`.\n * @param options - Optional configuration to override default settings.\n * @param options.locales - Array of valid locales. Defaults to the configured internationalization locales.\n * @param options.defaultLocale - The default locale to use as fallback. Defaults to the configured default locale.\n * @param options.mode - The routing mode (`'prefix'`, `'prefix-all'`, or `'no-prefix'`). Defaults to the configured routing mode.\n * @returns An object containing the validation result and the locale prefix.\n *\n * @example\n * // Check if 'en' is a valid locale\n * const { isValid, localePrefix } = validatePrefix('en');\n *\n * @example\n * // Check with custom options\n * const { isValid, localePrefix } = validatePrefix('fr', {\n * locales: ['en', 'fr', 'es'],\n * defaultLocale: 'en',\n * mode: 'prefix-all',\n * });\n */\nexport const validatePrefix = (\n locale: LocalesValues | undefined | null,\n options?: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: typeof configuration.routing.mode;\n }\n): ValidatePrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n ...options,\n };\n\n // If no locale provided (optional param), will use default\n // In `routing.mode = 'prefix-all'`, the locale is required to be a valid locale\n const { localePrefix } = getPrefix(locale || defaultLocale, {\n mode,\n locales,\n defaultLocale,\n });\n\n if (localePrefix === locale && locale === undefined) {\n return { isValid: true, localePrefix: undefined };\n }\n\n // Check if the provided locale is valid\n const isValid: boolean = locales.some((localeEl) => localeEl === locale);\n\n return { isValid: isValid, localePrefix };\n};\n"],"mappings":"sOAoCA,MAAa,GACX,EACA,IAKyB,CACzB,GAAM,CAAE,gBAAe,OAAM,WAAY,CACvC,cACEA,EAAAA,SAAe,sBAAsB,eAAiBC,EAAAA,eACxD,KAAMD,EAAAA,SAAe,SAAS,MAAQE,EAAAA,aACtC,QAASF,EAAAA,SAAe,sBAAsB,SAAWG,EAAAA,QACzD,GAAG,EACJ,CAIK,CAAE,gBAAiBC,EAAAA,UAAU,GAAU,EAAe,CAC1D,OACA,UACA,gBACD,CAAC,CASF,OAPI,IAAiB,GAAU,IAAW,IAAA,GACjC,CAAE,QAAS,GAAM,aAAc,IAAA,GAAW,CAM5C,CAAE,QAFgB,EAAQ,KAAM,GAAa,IAAa,EAAO,CAE7C,eAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{COOKIE_NAME as e,HEADER_NAME as t,LOCALE_STORAGE_NAME as n}from"@intlayer/config/defaultValues";const r=t=>{let{name:n,path:r,expires:i,domain:a,secure:o,sameSite:s,httpOnly:c}=t??{};return{name:n??e,attributes:{path:r,expires:i,domain:a,secure:o,sameSite:s,httpOnly:c}}},i=e=>{let{name:t}=e??{};return{name:t??n}},a=e=>{let{name:n}=e??{};return{name:n??t}},o=e=>e.type===`cookie`||`sameSite`in e||`httpOnly`in e||`secure`in e,s=e=>e===`cookie`||e===`localStorage`||e===`sessionStorage`||e===`header`,c=e=>{if(typeof e==`string`){if(!s(e))return{cookies:[],localStorage:[],sessionStorage:[],headers:[]};if(e===`cookie`)return{cookies:[r()]};if(e===`localStorage`)return{localStorage:[i()]};if(e===`sessionStorage`)return{sessionStorage:[i()]};if(e===`header`)return{headers:[a()]}}if(typeof e==`object`&&e){let t=e;if(o(t))return{cookies:[r(t)]};if(`type`in t&&t.type===`localStorage`){let{name:e,...n}=t;return{localStorage:[i({name:e,...n})]}}if(`type`in t&&t.type===`sessionStorage`){let{name:e,...n}=t;return{sessionStorage:[i({name:e,...n})]}}if(`type`in t&&t.type===`header`){let{name:e,...n}=t;return{headers:[a({name:e,...n})]}}let{name:n,...s}=t;return{localStorage:[i({name:n,...s})]}}return{cookies:[],localStorage:[],sessionStorage:[],headers:[]}},l=(e,t)=>({cookies:[...e.cookies,...t.cookies??[]],localStorage:[...e.localStorage,...t.localStorage??[]],sessionStorage:[...e.sessionStorage,...t.sessionStorage??[]],headers:[...e.headers,...t.headers??[]]}),u=e=>{let t={cookies:[],localStorage:[],sessionStorage:[],headers:[]};return e===!1||e===void 0?t:Array.isArray(e)?e.reduce((e,t)=>l(e,c(t)),t):l(t,c(e))};export{u as getStorageAttributes};
|
|
2
2
|
//# sourceMappingURL=getStorageAttributes.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageAttributes.mjs","names":[],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"getStorageAttributes.mjs","names":[],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '@intlayer/config/defaultValues';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n StorageAttributes,\n} from '@intlayer/types/config';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ntype CookieEntry = {\n name: string;\n attributes: Omit<CookiesAttributes, 'type' | 'name'>;\n};\n\ntype WebStorageEntry = {\n name: string;\n};\n\ntype HeaderEntry = {\n name: string;\n};\n\nexport type ProcessedStorageAttributes = {\n cookies: CookieEntry[];\n localStorage: WebStorageEntry[];\n sessionStorage: WebStorageEntry[];\n headers: HeaderEntry[];\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Creates a cookie entry with default values for missing attributes\n */\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n\n return {\n name: name ?? COOKIE_NAME,\n attributes: {\n path,\n expires,\n domain,\n secure,\n sameSite,\n httpOnly,\n },\n };\n};\n\n/**\n * Creates a web storage entry (localStorage or sessionStorage) with default name\n */\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? LOCALE_STORAGE_NAME,\n };\n};\n\n/**\n * Creates a header entry with default name\n */\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? HEADER_NAME,\n };\n};\n\n/**\n * Determines if a storage entry is a cookie based on its properties\n */\nconst isCookieEntry = (entry: any): boolean => {\n return (\n entry.type === 'cookie' ||\n 'sameSite' in entry ||\n 'httpOnly' in entry ||\n 'secure' in entry\n );\n};\n\n/**\n * Determines the storage type from a string literal\n */\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' => {\n return (\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header'\n );\n};\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Processes a single storage entry and returns the appropriate storage attributes\n */\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n // Handle string literals\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n\n if (entry === 'cookie') {\n return { cookies: [createCookieEntry()] };\n }\n\n if (entry === 'localStorage') {\n return { localStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'sessionStorage') {\n return { sessionStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'header') {\n return { headers: [createHeaderEntry()] };\n }\n }\n\n // Handle object entries\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | StorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n\n // Handle localStorage\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle sessionStorage\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { sessionStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle header\n if ('type' in typedEntry && typedEntry.type === 'header') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { headers: [createHeaderEntry({ name, ...rest })] };\n }\n\n // Default to localStorage for ambiguous objects\n const { name, ...rest } = typedEntry as Omit<StorageAttributes, 'type'>;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\n/**\n * Merges multiple partial storage attributes into a single result\n */\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => {\n return {\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [\n ...accumulated.localStorage,\n ...(partial.localStorage ?? []),\n ],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n headers: [...accumulated.headers, ...(partial.headers ?? [])],\n };\n};\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, and sessionStorage\n */\nexport const getStorageAttributes = (\n options: IntlayerConfig['routing']['storage']\n): ProcessedStorageAttributes => {\n const emptyResult: ProcessedStorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n headers: [],\n };\n\n // Storage is disabled\n if (options === false || options === undefined) {\n return emptyResult;\n }\n\n // Handle array of storage entries\n if (Array.isArray(options)) {\n return options.reduce<ProcessedStorageAttributes>((acc, entry) => {\n const partial = processStorageEntry(entry);\n return mergeStorageAttributes(acc, partial);\n }, emptyResult);\n }\n\n // Handle single storage entry\n const partial = processStorageEntry(options);\n\n return mergeStorageAttributes(emptyResult, partial);\n};\n"],"mappings":"uGAkDA,MAAM,EACJ,GACgB,CAChB,GAAM,CAAE,OAAM,OAAM,UAAS,SAAQ,SAAQ,WAAU,YACrD,GAAW,EAAE,CAEf,MAAO,CACL,KAAM,GAAQ,EACd,WAAY,CACV,OACA,UACA,SACA,SACA,WACA,WACD,CACF,EAMG,EACJ,GACoB,CACpB,GAAM,CAAE,QAAS,GAAW,EAAE,CAE9B,MAAO,CACL,KAAM,GAAQ,EACf,EAMG,EACJ,GACgB,CAChB,GAAM,CAAE,QAAS,GAAW,EAAE,CAE9B,MAAO,CACL,KAAM,GAAQ,EACf,EAMG,EAAiB,GAEnB,EAAM,OAAS,UACf,aAAc,GACd,aAAc,GACd,WAAY,EAOV,EACJ,GAGE,IAAU,UACV,IAAU,gBACV,IAAU,kBACV,IAAU,SAWR,EACJ,GACwC,CAExC,GAAI,OAAO,GAAU,SAAU,CAC7B,GAAI,CAAC,EAAc,EAAM,CACvB,MAAO,CAAE,QAAS,EAAE,CAAE,aAAc,EAAE,CAAE,eAAgB,EAAE,CAAE,QAAS,EAAE,CAAE,CAG3E,GAAI,IAAU,SACZ,MAAO,CAAE,QAAS,CAAC,GAAmB,CAAC,CAAE,CAG3C,GAAI,IAAU,eACZ,MAAO,CAAE,aAAc,CAAC,GAAuB,CAAC,CAAE,CAGpD,GAAI,IAAU,iBACZ,MAAO,CAAE,eAAgB,CAAC,GAAuB,CAAC,CAAE,CAGtD,GAAI,IAAU,SACZ,MAAO,CAAE,QAAS,CAAC,GAAmB,CAAC,CAAE,CAK7C,GAAI,OAAO,GAAU,UAAY,EAAgB,CAC/C,IAAM,EAAa,EAEnB,GAAI,EAAc,EAAW,CAC3B,MAAO,CAAE,QAAS,CAAC,EAAkB,EAAgC,CAAC,CAAE,CAI1E,GAAI,SAAU,GAAc,EAAW,OAAS,eAAgB,CAC9D,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,aAAc,CAAC,EAAsB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAIrE,GAAI,SAAU,GAAc,EAAW,OAAS,iBAAkB,CAChE,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,eAAgB,CAAC,EAAsB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAIvE,GAAI,SAAU,GAAc,EAAW,OAAS,SAAU,CACxD,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,QAAS,CAAC,EAAkB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAI5D,GAAM,CAAE,OAAM,GAAG,GAAS,EAC1B,MAAO,CAAE,aAAc,CAAC,EAAsB,CAAE,OAAM,GAAG,EAAM,CAAC,CAAC,CAAE,CAGrE,MAAO,CAAE,QAAS,EAAE,CAAE,aAAc,EAAE,CAAE,eAAgB,EAAE,CAAE,QAAS,EAAE,CAAE,EAMrE,GACJ,EACA,KAEO,CACL,QAAS,CAAC,GAAG,EAAY,QAAS,GAAI,EAAQ,SAAW,EAAE,CAAE,CAC7D,aAAc,CACZ,GAAG,EAAY,aACf,GAAI,EAAQ,cAAgB,EAAE,CAC/B,CACD,eAAgB,CACd,GAAG,EAAY,eACf,GAAI,EAAQ,gBAAkB,EAAE,CACjC,CACD,QAAS,CAAC,GAAG,EAAY,QAAS,GAAI,EAAQ,SAAW,EAAE,CAAE,CAC9D,EASU,EACX,GAC+B,CAC/B,IAAM,EAA0C,CAC9C,QAAS,EAAE,CACX,aAAc,EAAE,CAChB,eAAgB,EAAE,CAClB,QAAS,EAAE,CACZ,CAkBD,OAfI,IAAY,IAAS,IAAY,IAAA,GAC5B,EAIL,MAAM,QAAQ,EAAQ,CACjB,EAAQ,QAAoC,EAAK,IAE/C,EAAuB,EADd,EAAoB,EAAM,CACC,CAC1C,EAAY,CAMV,EAAuB,EAFd,EAAoB,EAAQ,CAEO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely processed.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n\n // Don't process Promises (e.g., Next.js 15+ params)\n if (value instanceof Promise || typeof (value as any).then === 'function') {\n return false;\n }\n\n // Don't process React elements or other framework VNodes\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n\n // Only process plain objects and arrays\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects.\n * Resembles the behavior of `defu` but respects `isPlainObject` to avoid merging React elements.\n * Arrays are replaced, not merged.\n */\nconst deepMergeObjects = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n\n if (Array.isArray(target)) return target;\n\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n for (const key of Object.keys(source)) {\n if (key === '__proto__' || key === 'constructor') continue;\n\n if (Object.hasOwn(target, key)) {\n result[key] = deepMergeObjects(target[key], source[key]);\n } else {\n result[key] = source[key];\n }\n }\n return result;\n }\n\n return target;\n};\n\n/**\n * Recursively removes undefined values from an object.\n * Handles circular references by tracking visited objects.\n */\nconst removeUndefinedValues = <T>(\n object: T,\n visited = new WeakSet<object>()\n): T => {\n if (typeof object !== 'object' || object === null) {\n return object;\n }\n\n // Handle circular references - return original to avoid infinite recursion\n if (visited.has(object)) {\n return object;\n }\n visited.add(object);\n\n // Don't process non-plain objects (Promises, React elements, etc.)\n if (!isPlainObject(object)) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map((item) => removeUndefinedValues(item, visited)) as T;\n }\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(object)) {\n if (value !== undefined) {\n result[key] = removeUndefinedValues(value, visited);\n }\n }\n return result as T;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const results: Content[] = [];\n\n const getContent = (loc: string) =>\n languageContent[loc as keyof typeof languageContent];\n\n // Get Target Content\n const content = getContent(locale);\n if (typeof content === 'string') {\n return content;\n } else if (content !== undefined) {\n results.push(content);\n }\n\n // Get Target Generic Content (e.g. 'en' from 'en-US')\n if (locale.includes('-')) {\n const genericLocale = locale.split('-')[0];\n if (genericLocale in languageContent) {\n const genericContent = getContent(genericLocale);\n\n if (typeof genericContent === 'string') {\n // If we haven't found specific content yet, return generic string\n if (results.length === 0) return genericContent;\n } else if (genericContent !== undefined) {\n results.push(genericContent);\n }\n }\n }\n\n // Get Fallback Content\n if (fallback !== undefined && fallback !== locale) {\n // 3a. Fallback Specific\n if (fallback in languageContent) {\n const fallbackContent = getContent(fallback);\n\n if (typeof fallbackContent === 'string') {\n if (results.length === 0) return fallbackContent;\n } else if (fallbackContent !== undefined) {\n results.push(fallbackContent);\n }\n }\n\n // Fallback Generic (The missing piece: e.g. 'en' from 'en-GB' fallback)\n if (fallback.includes('-')) {\n const genericFallback = fallback.split('-')[0];\n const genericLocale = locale.split('-')[0];\n\n // Only add if it's different from the target generic (to avoid duplication)\n // and exists in the dictionary\n if (\n genericFallback !== genericLocale &&\n genericFallback in languageContent\n ) {\n const genericFallbackContent = getContent(genericFallback);\n\n if (typeof genericFallbackContent === 'string') {\n if (results.length === 0) return genericFallbackContent;\n } else if (genericFallbackContent !== undefined) {\n results.push(genericFallbackContent);\n }\n }\n }\n }\n\n if (results.length === 0) {\n return undefined as Content;\n }\n\n // Clean undefined values so they don't overwrite fallbacks\n // Order: [Target, Generic, Fallback, FallbackGeneric]\n // defu first argument takes precedence, so Target wins\n const cleanResults = results\n .filter((item) => typeof item !== 'undefined')\n .map((item) => removeUndefinedValues(item));\n\n // If only one result, return it directly (no merging needed)\n if (cleanResults.length === 1) {\n return cleanResults[0];\n }\n\n // If the first result is an array, return it directly (arrays replace, don't merge)\n // defu would incorrectly convert arrays to objects with numeric keys\n if (Array.isArray(cleanResults[0])) {\n return cleanResults[0];\n }\n\n // Merge objects with custom merge - first argument takes precedence\n // Cast to object[] since by this point we've already returned early for strings, arrays, and single results\n return (cleanResults as object[]).reduce((acc, curr) =>\n deepMergeObjects(acc, curr)\n ) as Content;\n};\n"],"mappings":"AASA,MAAM,EAAiB,GAA4B,CAWjD,GAVsB,OAAO,GAAU,WAAnC,GAKA,aAAiB,SAAW,OAAQ,EAAc,MAAS,YAM5D,EAAc,WAAa,IAAA,IAC3B,EAAc,cAAgB,IAAA,IAC9B,EAAc,WAAa,IAAA,IAC3B,EAAc,QAAU,IAAA,GAEzB,MAAO,GAIT,IAAM,EAAQ,OAAO,eAAe,EAAM,CAC1C,OAAO,IAAU,OAAO,WAAa,IAAU,MAAQ,MAAM,QAAQ,EAAM,EAQvE,GAAoB,EAAa,IAAqB,CAC1D,GAAI,IAAW,IAAA,GAAW,OAAO,EAGjC,GAFI,IAAW,IAAA,IAEX,MAAM,QAAQ,EAAO,CAAE,OAAO,EAElC,GAAI,EAAc,EAAO,EAAI,EAAc,EAAO,CAAE,CAClD,IAAM,EAAS,CAAE,GAAG,EAAQ,CAC5B,IAAK,IAAM,KAAO,OAAO,KAAK,EAAO,CAC/B,IAAQ,aAAe,IAAQ,gBAE/B,OAAO,OAAO,EAAQ,EAAI,CAC5B,EAAO,GAAO,EAAiB,EAAO,GAAM,EAAO,GAAK,CAExD,EAAO,GAAO,EAAO,IAGzB,OAAO,EAGT,OAAO,GAOH,GACJ,EACA,EAAU,IAAI,UACR,CAYN,GAXI,OAAO,GAAW,WAAY,GAK9B,EAAQ,IAAI,EAAO,GAGvB,EAAQ,IAAI,EAAO,CAGf,CAAC,EAAc,EAAO,EACxB,OAAO,EAGT,GAAI,MAAM,QAAQ,EAAO,CACvB,OAAO,EAAO,IAAK,GAAS,EAAsB,EAAM,EAAQ,CAAC,CAGnE,IAAM,EAAkC,EAAE,CAC1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAO,CAC3C,IAAU,IAAA,KACZ,EAAO,GAAO,EAAsB,EAAO,EAAQ,EAGvD,OAAO,GA0BI,GACX,EACA,EACA,IACY,CACZ,IAAM,EAAqB,EAAE,CAEvB,EAAc,GAClB,EAAgB,GAGZ,EAAU,EAAW,EAAO,CAClC,GAAI,OAAO,GAAY,SACrB,OAAO,EAMT,GALW,IAAY,IAAA,IACrB,EAAQ,KAAK,EAAQ,CAInB,EAAO,SAAS,IAAI,CAAE,CACxB,IAAM,EAAgB,EAAO,MAAM,IAAI,CAAC,GACxC,GAAI,KAAiB,EAAiB,CACpC,IAAM,EAAiB,EAAW,EAAc,CAEhD,GAAI,OAAO,GAAmB,aAExB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAmB,IAAA,IAC5B,EAAQ,KAAK,EAAe,EAMlC,GAAI,IAAa,IAAA,IAAa,IAAa,EAAQ,CAEjD,GAAI,KAAY,EAAiB,CAC/B,IAAM,EAAkB,EAAW,EAAS,CAE5C,GAAI,OAAO,GAAoB,aACzB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAoB,IAAA,IAC7B,EAAQ,KAAK,EAAgB,CAKjC,GAAI,EAAS,SAAS,IAAI,CAAE,CAC1B,IAAM,EAAkB,EAAS,MAAM,IAAI,CAAC,GAK5C,GACE,IALoB,EAAO,MAAM,IAAI,CAAC,IAMtC,KAAmB,EACnB,CACA,IAAM,EAAyB,EAAW,EAAgB,CAE1D,GAAI,OAAO,GAA2B,aAChC,EAAQ,SAAW,EAAG,OAAO,OACxB,IAA2B,IAAA,IACpC,EAAQ,KAAK,EAAuB,GAM5C,GAAI,EAAQ,SAAW,EACrB,OAMF,IAAM,EAAe,EAClB,OAAQ,GAAgB,IAAS,OAAY,CAC7C,IAAK,GAAS,EAAsB,EAAK,CAAC,CAe7C,OAZI,EAAa,SAAW,GAMxB,MAAM,QAAQ,EAAa,GAAG,CACzB,EAAa,GAKd,EAA0B,QAAQ,EAAK,IAC7C,EAAiB,EAAK,EAAK,CAC5B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getLocaleFromStorage as e}from"../utils/localeStorage.mjs";import{localeResolver as t}from"./localeResolver.mjs";import{getPreferredLanguages as n}from"./localeDetector.mjs";import{
|
|
1
|
+
import{getLocaleFromStorage as e}from"../utils/localeStorage.mjs";import{localeResolver as t}from"./localeResolver.mjs";import{getPreferredLanguages as n}from"./localeDetector.mjs";import{DEFAULT_LOCALE as r,LOCALES as i}from"@intlayer/config/defaultValues";import a from"@intlayer/config/built";const o=async(o={})=>{let s=a?.internationalization?.defaultLocale??r,c=a?.internationalization?.locales??i,l=e({getCookie:o.getCookie,getHeader:o.getHeader});if(l)return l;let u=o.getHeader?.(`accept-language`);return u&&t(n(u,c),c,s)||s};export{o as getLocale};
|
|
2
2
|
//# sourceMappingURL=getLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DEFAULT_LOCALE, LOCALES } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getLocaleFromStorage } from '../utils/localeStorage';\nimport { getPreferredLanguages } from './localeDetector';\nimport { localeResolver } from './localeResolver';\n\nexport type RequestContext = {\n getHeader?: (name: string) => string | null | undefined;\n getCookie?: (name: string) => string | null | undefined;\n};\n\nexport const getLocale = async (ctx: RequestContext = {}): Promise<Locale> => {\n const defaultLocale =\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE;\n const availableLocales =\n configuration?.internationalization?.locales ?? LOCALES;\n\n // Try locale from storage (cookie or header)\n const storedLocale = getLocaleFromStorage({\n getCookie: ctx.getCookie,\n getHeader: ctx.getHeader,\n });\n\n if (storedLocale) {\n return storedLocale;\n }\n\n // Fallback to Accept-Language negotiation\n const acceptLanguageHeader = ctx.getHeader?.('accept-language');\n\n if (!acceptLanguageHeader) {\n return defaultLocale;\n }\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales\n );\n\n const userFallbackLocale = localeResolver(\n preferredLocaleStrings,\n availableLocales,\n defaultLocale\n );\n\n if (userFallbackLocale) {\n return userFallbackLocale;\n }\n\n // Default locale\n return defaultLocale;\n};\n"],"mappings":"wSAYA,MAAa,EAAY,MAAO,EAAsB,EAAE,GAAsB,CAC5E,IAAM,EACJ,GAAe,sBAAsB,eAAiB,EAClD,EACJ,GAAe,sBAAsB,SAAW,EAG5C,EAAe,EAAqB,CACxC,UAAW,EAAI,UACf,UAAW,EAAI,UAChB,CAAC,CAEF,GAAI,EACF,OAAO,EAIT,IAAM,EAAuB,EAAI,YAAY,kBAAkB,CAsB/D,OApBK,GASsB,EALI,EAC7B,EACA,EACD,CAIC,EACA,EACD,EAZQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{checkIsURLAbsolute as e}from"../utils/checkIsURLAbsolute.mjs";import{
|
|
1
|
+
import{checkIsURLAbsolute as e}from"../utils/checkIsURLAbsolute.mjs";import{DEFAULT_LOCALE as t,LOCALES as n,ROUTING_MODE as r}from"@intlayer/config/defaultValues";import i from"@intlayer/config/built";const a=(a=`/`,o)=>{let{defaultLocale:s,locales:c,mode:l}={defaultLocale:i?.internationalization?.defaultLocale??t,mode:i?.routing?.mode??r,locales:i?.internationalization?.locales??n,...o};if(!s||!c)return t;let u=e(a),d=a;a?.endsWith(`/`)&&a.length>1&&(d=a.slice(0,-1));let f=u?new URL(d):new URL(d,`http://example.com`);if(l===`search-params`){let e=f.searchParams.get(`locale`);return e&&c.includes(e)?e:s}if(l===`no-prefix`)return s;let p=f.pathname.split(`/`)[1];if(p&&c.includes(p))return p;if(l===`prefix-no-default`)return s};export{a as getLocaleFromPath};
|
|
2
2
|
//# sourceMappingURL=getLocaleFromPath.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromPath.mjs","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"getLocaleFromPath.mjs","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\ntype GetLocaleFromPathOptions = {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n};\n\n/**\n * Extracts the locale segment from the given URL or pathname based on the routing mode.\n *\n * Mode Behaviors:\n * - 'prefix-no-default': Checks path prefiIf no prefix found, assumes default locale.\n * - 'prefix-all': Checks path prefix.\n * - 'search-params': Checks for 'locale' query parameter.\n * - 'no-prefix': Returns undefined (or default if fallback is true).\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @returns The detected locale, default locale (if fallback/implicit), or undefined.\n */\nexport const getLocaleFromPath = (\n inputUrl: string = '/',\n options?: GetLocaleFromPathOptions\n): Locale | undefined => {\n const { defaultLocale, locales, mode } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n ...options,\n };\n\n if (!defaultLocale || !locales) {\n return DEFAULT_LOCALE;\n }\n\n // Prepare the URL object\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n let fixedInputUrl = inputUrl;\n\n if (inputUrl?.endsWith('/') && inputUrl.length > 1) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n // Handle 'search-params' mode\n // Example: /dashboard?locale=fr\n if (mode === 'search-params') {\n const localeParam = url.searchParams.get('locale');\n\n if (localeParam && locales.includes(localeParam)) {\n return localeParam as Locale;\n }\n\n return defaultLocale as Locale;\n }\n\n // Handle 'no-prefix' mode\n // The locale is not stored in the URL path.\n if (mode === 'no-prefix') {\n return defaultLocale as Locale;\n }\n\n // Handle Prefix Modes ('prefix-all' | 'prefix-no-default')\n const pathname = url.pathname;\n\n // Split the pathname to extract the first segment\n // pathSegments[0] is empty string because path starts with /\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1];\n\n // Check if the first segment is a valid supported locale\n const isSegmentLocale = firstSegment && locales.includes(firstSegment);\n\n if (isSegmentLocale) {\n return firstSegment as Locale;\n }\n\n // If the first segment is NOT a locale (e./dashboard), handle based on mode\n if (mode === 'prefix-no-default') {\n // In this mode, absence of a prefix implies the default locale\n return defaultLocale as Locale;\n }\n\n return undefined;\n};\n"],"mappings":"0MA6BA,MAAa,GACX,EAAmB,IACnB,IACuB,CACvB,GAAM,CAAE,gBAAe,UAAS,QAAS,CACvC,cACE,GAAe,sBAAsB,eAAiB,EACxD,KAAM,GAAe,SAAS,MAAQ,EACtC,QAAS,GAAe,sBAAsB,SAAW,EACzD,GAAG,EACJ,CAED,GAAI,CAAC,GAAiB,CAAC,EACrB,OAAO,EAIT,IAAM,EAAgB,EAAmB,EAAS,CAC9C,EAAgB,EAEhB,GAAU,SAAS,IAAI,EAAI,EAAS,OAAS,IAC/C,EAAgB,EAAS,MAAM,EAAG,GAAG,EAIvC,IAAM,EAAM,EACR,IAAI,IAAI,EAAc,CACtB,IAAI,IAAI,EAAe,qBAAqB,CAIhD,GAAI,IAAS,gBAAiB,CAC5B,IAAM,EAAc,EAAI,aAAa,IAAI,SAAS,CAMlD,OAJI,GAAe,EAAQ,SAAS,EAAY,CACvC,EAGF,EAKT,GAAI,IAAS,YACX,OAAO,EAST,IAAM,EALW,EAAI,SAIS,MAAM,IAAI,CACN,GAKlC,GAFwB,GAAgB,EAAQ,SAAS,EAAa,CAGpE,OAAO,EAIT,GAAI,IAAS,oBAEX,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{checkIsURLAbsolute as e}from"../utils/checkIsURLAbsolute.mjs";import{getPathWithoutLocale as t}from"./getPathWithoutLocale.mjs";import{getPrefix as n}from"./getPrefix.mjs";import{getCanonicalPath as r,getLocalizedPath as i,getRewriteRules as a}from"./rewriteUtils.mjs";import{
|
|
1
|
+
import{checkIsURLAbsolute as e}from"../utils/checkIsURLAbsolute.mjs";import{getPathWithoutLocale as t}from"./getPathWithoutLocale.mjs";import{getPrefix as n}from"./getPrefix.mjs";import{getCanonicalPath as r,getLocalizedPath as i,getRewriteRules as a}from"./rewriteUtils.mjs";import{DEFAULT_LOCALE as o,LOCALES as s,ROUTING_MODE as c}from"@intlayer/config/defaultValues";import l from"@intlayer/config/built";const u=(u,d=l?.internationalization?.defaultLocale,f={})=>{let{defaultLocale:p,mode:m,locales:h,rewrite:g}={defaultLocale:l?.internationalization?.defaultLocale??o,mode:l?.routing?.mode??c,locales:l?.internationalization?.locales??s,rewrite:l?.routing?.rewrite,...f},_=t(u,h),v=a(g,`url`);if(m===`no-prefix`)return i(r(_,void 0,v),d,v).path;let y=e(_),b=y?new URL(_):new URL(_,`http://example.com`),x=y?`${b.protocol}//${b.host}`:``,S=i(r(b.pathname,void 0,v),d,v).path;if(m===`search-params`){let e=new URLSearchParams(b.search);e.set(`locale`,d.toString());let t=e.toString(),n=t?`${S}?${t}`:S;return y?`${x}${n}${b.hash}`:`${n}${b.hash}`}let{prefix:C}=n(d,{defaultLocale:p,mode:m,locales:h}),w=`/${C}${S}`;return w=w.replaceAll(/\/+/g,`/`),w.length>1&&w.endsWith(`/`)&&(w=w.slice(0,-1)),y?`${x}${w}${b.search}${b.hash}`:`${w}${b.search}${b.hash}`};export{u as getLocalizedUrl};
|
|
2
2
|
//# sourceMappingURL=getLocalizedUrl.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedUrl.mjs","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"getLocalizedUrl.mjs","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\nimport { getPrefix } from './getPrefix';\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\n} from './rewriteUtils';\n\n/**\n * Generate URL by prefixing the given URL with the referenced locale or adding search parameters\n * based on the routing mode. Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-no-default' });\n * // Returns '/fr/about' for the French locale\n * // Returns '/about' for the English locale (default)\n *\n * // prefix-all mode\n * getLocalizedUrl('/about', 'en', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-all' });\n * // Returns '/en/about' for the English locale\n * // Returns '/fr/about' for the French locale\n *\n * // search-params mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'search-params' });\n * // Returns '/about?locale=fr' for the French locale\n *\n * // no-prefix mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'no-prefix' });\n * // Returns '/about' for any locale\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param currentLocale - The current locale.\n * @param options - Configuration options\n * @param options.locales - Optional array of supported locales. Defaults to configured locales.\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns The localized URL for the current locale.\n */\nexport const getLocalizedUrl = (\n url: string,\n currentLocale: LocalesValues = configuration?.internationalization\n ?.defaultLocale,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n } = {}\n): string => {\n const { defaultLocale, mode, locales, rewrite } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n rewrite: configuration?.routing?.rewrite,\n ...options,\n };\n\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n const urlRewriteRules = getRewriteRules(rewrite, 'url');\n\n if (mode === 'no-prefix') {\n // Resolve to canonical path first from the potentially localized input URL\n const canonicalPathname = getCanonicalPath(\n urlWithoutLocale,\n undefined,\n urlRewriteRules\n );\n\n // Localize the canonical path for the target locale\n return getLocalizedPath(\n canonicalPathname,\n currentLocale as Locale,\n urlRewriteRules\n ).path;\n }\n\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Resolve to canonical path first\n const canonicalPathname = getCanonicalPath(\n parsedUrl.pathname,\n undefined,\n urlRewriteRules\n );\n\n // Localize the canonical path for the target locale\n const translatedPathname = getLocalizedPath(\n canonicalPathname,\n currentLocale as Locale,\n urlRewriteRules\n ).path;\n\n if (mode === 'search-params') {\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', currentLocale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${translatedPathname}?${queryString}`\n : translatedPathname;\n\n return isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n }\n\n const { prefix } = getPrefix(currentLocale, {\n defaultLocale,\n mode,\n locales,\n });\n\n let localizedPath = `/${prefix}${translatedPathname}`;\n\n localizedPath = localizedPath.replaceAll(/\\/+/g, '/');\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n const finalUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n\n return finalUrl;\n};\n"],"mappings":"yZAsDA,MAAa,GACX,EACA,EAA+B,GAAe,sBAC1C,cACJ,EAKI,EAAE,GACK,CACX,GAAM,CAAE,gBAAe,OAAM,UAAS,WAAY,CAChD,cACE,GAAe,sBAAsB,eAAiB,EACxD,KAAM,GAAe,SAAS,MAAQ,EACtC,QAAS,GAAe,sBAAsB,SAAW,EACzD,QAAS,GAAe,SAAS,QACjC,GAAG,EACJ,CAEK,EAAmB,EAAqB,EAAK,EAAQ,CAErD,EAAkB,EAAgB,EAAS,MAAM,CAEvD,GAAI,IAAS,YASX,OAAO,EAPmB,EACxB,EACA,IAAA,GACA,EACD,CAKC,EACA,EACD,CAAC,KAGJ,IAAM,EAAgB,EAAmB,EAAiB,CAEpD,EAAY,EACd,IAAI,IAAI,EAAiB,CACzB,IAAI,IAAI,EAAkB,qBAAqB,CAE7C,EAAU,EACZ,GAAG,EAAU,SAAS,IAAI,EAAU,OACpC,GAUE,EAAqB,EAPD,EACxB,EAAU,SACV,IAAA,GACA,EACD,CAKC,EACA,EACD,CAAC,KAEF,GAAI,IAAS,gBAAiB,CAC5B,IAAM,EAAe,IAAI,gBAAgB,EAAU,OAAO,CAC1D,EAAa,IAAI,SAAU,EAAc,UAAU,CAAC,CAEpD,IAAM,EAAc,EAAa,UAAU,CACrC,EAAgB,EAClB,GAAG,EAAmB,GAAG,IACzB,EAEJ,OAAO,EACH,GAAG,IAAU,IAAgB,EAAU,OACvC,GAAG,IAAgB,EAAU,OAGnC,GAAM,CAAE,UAAW,EAAU,EAAe,CAC1C,gBACA,OACA,UACD,CAAC,CAEE,EAAgB,IAAI,IAAS,IAYjC,MAVA,GAAgB,EAAc,WAAW,OAAQ,IAAI,CAEjD,EAAc,OAAS,GAAK,EAAc,SAAS,IAAI,GACzD,EAAgB,EAAc,MAAM,EAAG,GAAG,EAG3B,EACb,GAAG,IAAU,IAAgB,EAAU,SAAS,EAAU,OAC1D,GAAG,IAAgB,EAAU,SAAS,EAAU"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getLocalizedUrl as e}from"./getLocalizedUrl.mjs";import{
|
|
1
|
+
import{getLocalizedUrl as e}from"./getLocalizedUrl.mjs";import{DEFAULT_LOCALE as t,LOCALES as n,ROUTING_MODE as r}from"@intlayer/config/defaultValues";import i from"@intlayer/config/built";const a=(a,o={})=>{let{defaultLocale:s,mode:c,locales:l,rewrite:u}={defaultLocale:i?.internationalization?.defaultLocale??t,mode:i?.routing?.mode??r,locales:i?.internationalization?.locales??n,rewrite:i?.routing?.rewrite,...o};return(l??[]).reduce((t,n)=>(t[n]=e(a,n,{locales:l,defaultLocale:s,mode:c,rewrite:u}),t),{})};export{a as getMultilingualUrls};
|
|
2
2
|
//# sourceMappingURL=getMultilingualUrls.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualUrls.mjs","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"getMultilingualUrls.mjs","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getLocalizedUrl } from './getLocalizedUrl';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'search-params' })\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param options - Configuration options\n * @param options.locales - Optional array of supported locales. Defaults to configured locales.\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n } = {}\n): StrictModeLocaleMap<string> => {\n const { defaultLocale, mode, locales, rewrite } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n rewrite: configuration?.routing?.rewrite,\n ...options,\n };\n\n // Generate multilingual URLs by iterating over each locale and calling getLocalizedUrl\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Get the localized URL for this locale\n const localizedUrl = getLocalizedUrl(url, locale, {\n locales,\n defaultLocale,\n mode,\n rewrite,\n });\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":"6LA+CA,MAAa,GACX,EACA,EAKI,EAAE,GAC0B,CAChC,GAAM,CAAE,gBAAe,OAAM,UAAS,WAAY,CAChD,cACE,GAAe,sBAAsB,eAAiB,EACxD,KAAM,GAAe,SAAS,MAAQ,EACtC,QAAS,GAAe,sBAAsB,SAAW,EACzD,QAAS,GAAe,SAAS,QACjC,GAAG,EACJ,CAqBD,OAlB0B,GAAW,EAAE,EAAE,QACtC,EAAK,KAUJ,EAAI,GARiB,EAAgB,EAAK,EAAQ,CAChD,UACA,gBACA,OACA,UACD,CAAC,CAKK,GAET,EAAE,CACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{DEFAULT_LOCALE as e,LOCALES as t,ROUTING_MODE as n}from"@intlayer/config/defaultValues";import r from"@intlayer/config/built";const i=(i,a={})=>{let{defaultLocale:o,mode:s,locales:c}={defaultLocale:r?.internationalization?.defaultLocale??e,mode:r?.routing?.mode??n,locales:r?.internationalization?.locales??t,...a};return!i||!c.includes(i)?{prefix:``,localePrefix:void 0}:s===`prefix-all`||s===`prefix-no-default`&&o!==i?{prefix:`${i}/`,localePrefix:i}:{prefix:``,localePrefix:void 0}};export{i as getPrefix};
|
|
2
2
|
//# sourceMappingURL=getPrefix.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrefix.mjs","names":[],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"getPrefix.mjs","names":[],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type GetPrefixOptions = {\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n};\n\nexport type GetPrefixResult = {\n /**\n * The complete base URL path with leading and trailing slashes.\n *\n * @example\n * // https://example.com/fr/about -> '/fr'\n * // https://example.com/about -> ''\n */\n prefix: string;\n /**\n * The locale identifier without slashes.\n *\n * @example\n * // https://example.com/fr/about -> 'fr'\n * // https://example.com/about -> undefined\n */\n localePrefix: Locale | undefined;\n};\n\n/**\n * Determines the URL prefix for a given locale based on the routing mode configuration.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode with default locale\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // prefix-no-default mode with non-default locale\n * getPrefix('fr', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '/fr', localePrefix: 'fr' }\n *\n * // prefix-all mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { prefix: '/en', localePrefix: locale }\n *\n * // search-params mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'search-params' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // no-prefix mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { prefix: '', localePrefix: undefined }\n * ```\n *\n * @param locale - The locale to check for prefix. If not provided, uses configured default locale.\n * @param options - Configuration options\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object containing pathPrefix, prefix, and localePrefix for the given locale.\n */\nexport const getPrefix = (\n locale: LocalesValues | undefined,\n options: {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n } = {}\n): GetPrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n ...options,\n };\n\n if (!locale || !locales.includes(locale)) {\n return {\n prefix: '',\n localePrefix: undefined,\n };\n }\n\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n mode === 'prefix-all' ||\n (mode === 'prefix-no-default' && defaultLocale !== locale);\n\n if (shouldPrefix) {\n return {\n prefix: `${locale}/`,\n localePrefix: locale as Locale,\n };\n }\n\n return {\n prefix: '',\n localePrefix: undefined,\n };\n};\n"],"mappings":"qIAmEA,MAAa,GACX,EACA,EAII,EAAE,GACc,CACpB,GAAM,CAAE,gBAAe,OAAM,WAAY,CACvC,cACE,GAAe,sBAAsB,eAAiB,EACxD,KAAM,GAAe,SAAS,MAAQ,EACtC,QAAS,GAAe,sBAAsB,SAAW,EACzD,GAAG,EACJ,CAqBD,MAnBI,CAAC,GAAU,CAAC,EAAQ,SAAS,EAAO,CAC/B,CACL,OAAQ,GACR,aAAc,IAAA,GACf,CAKD,IAAS,cACR,IAAS,qBAAuB,IAAkB,EAG5C,CACL,OAAQ,GAAG,EAAO,GAClB,aAAc,EACf,CAGI,CACL,OAAQ,GACR,aAAc,IAAA,GACf"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{DEFAULT_LOCALE as e}from"@intlayer/config/defaultValues";import t from"@intlayer/config/built";const n=(e,t,n)=>n===`no-prefix`||n===`search-params`?!1:n===`prefix-all`?!0:e!==t,r=(r,i=t?.internationalization.locales??[],a=t?.internationalization.defaultLocale??e,o=t?.routing?.mode??`prefix-no-default`)=>(i??[]).map(e=>r({locale:e,defaultLocale:a,locales:i,isDefault:e===a,urlPrefix:n(e,a,o)?`/${e}`:``})),i=(r,i=t?.internationalization.locales??[],a=t?.internationalization.defaultLocale??e,o=t?.routing?.mode??`prefix-no-default`)=>i.flatMap(e=>r({locale:e,defaultLocale:a,locales:i,isDefault:e===a,urlPrefix:n(e,a,o)?`/${e}`:``})),a=(r,i=t?.internationalization.locales??[],a=t?.internationalization.defaultLocale??e,o=t?.routing?.mode??`prefix-no-default`)=>(i??[]).reduce((e,t)=>(e[t]=r({locale:t,defaultLocale:a,locales:i,isDefault:t===a,urlPrefix:n(t,a,o)?`/${t}`:``}),e),{});export{i as localeFlatMap,r as localeMap,a as localeRecord};
|
|
2
2
|
//# sourceMappingURL=localeMapper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeMapper.mjs","names":[],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"localeMapper.mjs","names":[],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type LocaleData = {\n locale: Locale;\n defaultLocale: Locale;\n isDefault: boolean;\n locales: Locale[];\n urlPrefix: string;\n};\n\n/**\n * Determine if the locale should be prefixed in the URL based on routing mode\n */\nconst shouldPrefixLocale = (\n locale: LocalesValues,\n defaultLocale: LocalesValues,\n mode: 'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params'\n): boolean => {\n if (mode === 'no-prefix' || mode === 'search-params') {\n return false;\n }\n if (mode === 'prefix-all') {\n return true;\n }\n // 'prefix-no-default'\n return locale !== defaultLocale;\n};\n\n/**\n * Map the locale data to an array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * ({\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }),\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an object\n * @returns An array of objects\n */\nexport const localeMap = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n (locales ?? []).map((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' ,\n * path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' ,\n * path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' ,\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(\n mapper: (locale: LocaleData) => T[],\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n locales.flatMap((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Creates a record object mapping locales to values transformed by the mapper function\n *\n * @example\n * ```ts\n * const translations = localeRecord(({ locale }) =>\n * require(`./translations/${locale}.json`)\n * );\n *\n * // Result\n *\n * en: ... , // Content of translations/en.json\n * fr: ... , // Content of translations/fr.json\n * es: ...\n *\n * ```\n *\n * @param mapper - Function that takes locale data and returns a value for that locale\n * @param locales - Array of locale codes to map over (defaults to configured locales)\n * @param defaultLocale - The default locale (defaults to configured default)\n * @param mode - URL routing mode for locale handling (defaults to configured value)\n * @returns Record mapping locale codes to mapped values\n */\nexport const localeRecord = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): Record<LocalesValues, T> =>\n (locales ?? []).reduce(\n (acc, locale) => {\n acc[locale] = mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData);\n return acc;\n },\n {} as Record<LocalesValues, T>\n );\n"],"mappings":"sGAgBA,MAAM,GACJ,EACA,EACA,IAEI,IAAS,aAAe,IAAS,gBAC5B,GAEL,IAAS,aACJ,GAGF,IAAW,EA6BP,GACX,EACA,EAA2B,GAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+B,GAAe,qBAC3C,eAAiB,EACpB,EAIsB,GAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,IAAK,GACnB,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CA4BU,GACX,EACA,EAA2B,GAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+B,GAAe,qBAC3C,eAAiB,EACpB,EAIsB,GAAe,SAAS,MAAQ,sBAEtD,EAAQ,QAAS,GACf,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CAyBU,GACX,EACA,EAA2B,GAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+B,GAAe,qBAC3C,eAAiB,EACpB,EAIsB,GAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,QACb,EAAK,KACJ,EAAI,GAAU,EAAO,CACnB,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACT,GAET,EAAE,CACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getPrefix as e}from"./getPrefix.mjs";import{
|
|
1
|
+
import{getPrefix as e}from"./getPrefix.mjs";import{DEFAULT_LOCALE as t,LOCALES as n,ROUTING_MODE as r}from"@intlayer/config/defaultValues";import i from"@intlayer/config/built";const a=(a,o)=>{let{defaultLocale:s,mode:c,locales:l}={defaultLocale:i?.internationalization?.defaultLocale??t,mode:i?.routing?.mode??r,locales:i?.internationalization?.locales??n,...o},{localePrefix:u}=e(a||s,{mode:c,locales:l,defaultLocale:s});return u===a&&a===void 0?{isValid:!0,localePrefix:void 0}:{isValid:l.some(e=>e===a),localePrefix:u}};export{a as validatePrefix};
|
|
2
2
|
//# sourceMappingURL=validatePrefix.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatePrefix.mjs","names":[],"sources":["../../../src/localization/validatePrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"validatePrefix.mjs","names":[],"sources":["../../../src/localization/validatePrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getPrefix } from './getPrefix';\n\nexport type ValidatePrefixResult = {\n isValid: boolean;\n localePrefix: string | undefined;\n};\n\n/**\n * Checks whether a given locale is valid based on the configured locales.\n *\n * @param locale - The locale value to validate. Can be `undefined` or `null`.\n * @param options - Optional configuration to override default settings.\n * @param options.locales - Array of valid locales. Defaults to the configured internationalization locales.\n * @param options.defaultLocale - The default locale to use as fallback. Defaults to the configured default locale.\n * @param options.mode - The routing mode (`'prefix'`, `'prefix-all'`, or `'no-prefix'`). Defaults to the configured routing mode.\n * @returns An object containing the validation result and the locale prefix.\n *\n * @example\n * // Check if 'en' is a valid locale\n * const { isValid, localePrefix } = validatePrefix('en');\n *\n * @example\n * // Check with custom options\n * const { isValid, localePrefix } = validatePrefix('fr', {\n * locales: ['en', 'fr', 'es'],\n * defaultLocale: 'en',\n * mode: 'prefix-all',\n * });\n */\nexport const validatePrefix = (\n locale: LocalesValues | undefined | null,\n options?: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: typeof configuration.routing.mode;\n }\n): ValidatePrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? ROUTING_MODE,\n locales: configuration?.internationalization?.locales ?? LOCALES,\n ...options,\n };\n\n // If no locale provided (optional param), will use default\n // In `routing.mode = 'prefix-all'`, the locale is required to be a valid locale\n const { localePrefix } = getPrefix(locale || defaultLocale, {\n mode,\n locales,\n defaultLocale,\n });\n\n if (localePrefix === locale && locale === undefined) {\n return { isValid: true, localePrefix: undefined };\n }\n\n // Check if the provided locale is valid\n const isValid: boolean = locales.some((localeEl) => localeEl === locale);\n\n return { isValid: isValid, localePrefix };\n};\n"],"mappings":"iLAoCA,MAAa,GACX,EACA,IAKyB,CACzB,GAAM,CAAE,gBAAe,OAAM,WAAY,CACvC,cACE,GAAe,sBAAsB,eAAiB,EACxD,KAAM,GAAe,SAAS,MAAQ,EACtC,QAAS,GAAe,sBAAsB,SAAW,EACzD,GAAG,EACJ,CAIK,CAAE,gBAAiB,EAAU,GAAU,EAAe,CAC1D,OACA,UACA,gBACD,CAAC,CASF,OAPI,IAAiB,GAAU,IAAW,IAAA,GACjC,CAAE,QAAS,GAAM,aAAc,IAAA,GAAW,CAM5C,CAAE,QAFgB,EAAQ,KAAM,GAAa,IAAa,EAAO,CAE7C,eAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromPath-621W32QA.d.ts","names":[],"sources":["../../src/localization/getLocaleFromPath.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getLocaleFromPath-621W32QA.d.ts","names":[],"sources":["../../src/localization/getLocaleFromPath.ts"],"mappings":";;;;;KAWK,wBAAA;EACH,aAAA,GAAgB,aAAA;EAChB,OAAA,GAAU,aAAA;EACV,IAAA,GAAO,aAAA;AAAA;;;;;;;;;;;;;cAeI,iBAAA,GACX,QAAA,WACA,OAAA,GAAU,wBAAA,KACT,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedUrl-BbqeA3-W.d.ts","names":[],"sources":["../../src/localization/getLocalizedUrl.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"getLocalizedUrl-BbqeA3-W.d.ts","names":[],"sources":["../../src/localization/getLocalizedUrl.ts"],"mappings":";;;;;;AAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,eAAA,GACX,GAAA,UACA,aAAA,GAAe,aAAA,EAEf,OAAA;EACE,OAAA,GAAU,aAAA;EACV,aAAA,GAAgB,aAAA;EAChB,IAAA,GAAO,aAAA;EACP,OAAA,GAAU,aAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualUrls-CUxYYfA4.d.ts","names":[],"sources":["../../src/localization/getMultilingualUrls.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"getMultilingualUrls-CUxYYfA4.d.ts","names":[],"sources":["../../src/localization/getMultilingualUrls.ts"],"mappings":";;;;;;AA+CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,mBAAA,GACX,GAAA,UACA,OAAA;EACE,OAAA,GAAU,aAAA;EACV,aAAA,GAAgB,aAAA;EAChB,IAAA,GAAO,aAAA;EACP,OAAA,GAAU,aAAA;AAAA,MAEX,mBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrefix-X9XKkrZD.d.ts","names":[],"sources":["../../src/localization/getPrefix.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getPrefix-X9XKkrZD.d.ts","names":[],"sources":["../../src/localization/getPrefix.ts"],"mappings":";;;;;KAUY,gBAAA;EACV,aAAA,GAAgB,aAAA;EAChB,IAAA,GAAO,aAAA;AAAA;AAAA,KAGG,eAAA;EAHU;;;;;;;EAWpB,MAAA;EARyB;;;;;;;EAgBzB,YAAA,EAAc,MAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoCH,SAAA,GACX,MAAA,EAAQ,aAAA,cACR,OAAA;EACE,aAAA,GAAgB,aAAA;EAChB,OAAA,GAAU,aAAA;EACV,IAAA,GAAO,aAAA;AAAA,MAER,eAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageAttributes-CIO2xWqQ.d.ts","names":[],"sources":["../../src/getStorageAttributes.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getStorageAttributes-CIO2xWqQ.d.ts","names":[],"sources":["../../src/getStorageAttributes.ts"],"mappings":";;;KAeK,WAAA;EACH,IAAA;EACA,UAAA,EAAY,IAAA,CAAK,iBAAA;AAAA;AAAA,KAGd,eAAA;EACH,IAAA;AAAA;AAAA,KAGG,WAAA;EACH,IAAA;AAAA;AAAA,KAGU,0BAAA;EACV,OAAA,EAAS,WAAA;EACT,YAAA,EAAc,eAAA;EACd,cAAA,EAAgB,eAAA;EAChB,OAAA,EAAS,WAAA;AAAA;;AAXL;;;;;cAkMO,oBAAA,GACX,OAAA,EAAS,cAAA,2BACR,0BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslation-BG2Wg-af.d.ts","names":[],"sources":["../../src/interpreter/getTranslation.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getTranslation-BG2Wg-af.d.ts","names":[],"sources":["../../src/interpreter/getTranslation.ts"],"mappings":";;;;;AAyHA;;;;;;;;;;;;;;;;;;;;;cAAa,cAAA,qBACX,eAAA,EAAiB,mBAAA,CAAoB,OAAA,GACrC,MAAA,EAAQ,aAAA,EACR,QAAA,GAAW,aAAA,KACV,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatePrefix-Dtmg7QLq.d.ts","names":[],"sources":["../../src/localization/validatePrefix.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"validatePrefix-Dtmg7QLq.d.ts","names":[],"sources":["../../src/localization/validatePrefix.ts"],"mappings":";;;;KASY,oBAAA;EACV,OAAA;EACA,YAAA;AAAA;;;;AAyBF;;;;;;;;;;;;;;;;;;;cAAa,cAAA,GACX,MAAA,EAAQ,aAAA,qBACR,OAAA;EACE,OAAA,GAAU,aAAA;EACV,aAAA,GAAgB,aAAA;EAChB,IAAA,UAAc,aAAA,CAAc,OAAA,CAAQ,IAAA;AAAA,MAErC,oBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -168,11 +168,11 @@
|
|
|
168
168
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
169
169
|
},
|
|
170
170
|
"dependencies": {
|
|
171
|
-
"@intlayer/api": "8.4.
|
|
172
|
-
"@intlayer/config": "8.4.
|
|
173
|
-
"@intlayer/dictionaries-entry": "8.4.
|
|
174
|
-
"@intlayer/types": "8.4.
|
|
175
|
-
"@intlayer/unmerged-dictionaries-entry": "8.4.
|
|
171
|
+
"@intlayer/api": "8.4.3",
|
|
172
|
+
"@intlayer/config": "8.4.3",
|
|
173
|
+
"@intlayer/dictionaries-entry": "8.4.3",
|
|
174
|
+
"@intlayer/types": "8.4.3",
|
|
175
|
+
"@intlayer/unmerged-dictionaries-entry": "8.4.3",
|
|
176
176
|
"defu": "6.1.4"
|
|
177
177
|
},
|
|
178
178
|
"devDependencies": {
|