@intlayer/core 7.5.6 → 7.5.7
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/dist/esm/getStorageAttributes.cjs +134 -0
- package/dist/cjs/dist/esm/getStorageAttributes.cjs.map +1 -0
- package/dist/cjs/dist/esm/localization/localeResolver.cjs +28 -0
- package/dist/cjs/dist/esm/localization/localeResolver.cjs.map +1 -0
- package/dist/cjs/dist/esm/utils/getCookie.cjs +32 -0
- package/dist/cjs/dist/esm/utils/getCookie.cjs.map +1 -0
- package/dist/cjs/dist/esm/utils/localeStorage.cjs +61 -0
- package/dist/cjs/dist/esm/utils/localeStorage.cjs.map +1 -0
- package/dist/cjs/interpreter/getContent/getContent.cjs +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +6 -3
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +4 -3
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs +26 -23
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +38 -35
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/esm/dist/esm/getStorageAttributes.mjs +133 -0
- package/dist/esm/dist/esm/getStorageAttributes.mjs.map +1 -0
- package/dist/esm/dist/esm/localization/localeResolver.mjs +26 -0
- package/dist/esm/dist/esm/localization/localeResolver.mjs.map +1 -0
- package/dist/esm/dist/esm/utils/getCookie.mjs +31 -0
- package/dist/esm/dist/esm/utils/getCookie.mjs.map +1 -0
- package/dist/esm/dist/esm/utils/localeStorage.mjs +59 -0
- package/dist/esm/dist/esm/utils/localeStorage.mjs.map +1 -0
- package/dist/esm/interpreter/getContent/getContent.mjs +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +6 -3
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs +2 -1
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs +26 -23
- package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/utils/intl.mjs +38 -35
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +8 -8
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +8 -8
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +8 -8
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/localization/getLocaleFromPath.d.ts +14 -17
- package/dist/types/localization/getLocaleFromPath.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts +2 -2
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getMultilingualUrls.d.ts +2 -2
- package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
- package/dist/types/localization/getPrefix.d.ts +3 -3
- package/dist/types/localization/getPrefix.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts +3 -0
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport { getLocaleFromStorage, localeResolver } from '@intlayer/core';\nimport type { Locale } from '@intlayer/types';\nimport { getPreferredLanguages } from './localeDetector';\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 ??\n DefaultValues.Internationalization.DEFAULT_LOCALE;\n const availableLocales =\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.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":"
|
|
1
|
+
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport { getLocaleFromStorage, localeResolver } from '@intlayer/core';\nimport type { Locale } from '@intlayer/types';\nimport { getPreferredLanguages } from './localeDetector';\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 ??\n DefaultValues.Internationalization.DEFAULT_LOCALE;\n const availableLocales =\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.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":";;;;;;;AAWA,MAAa,YAAY,OAAO,MAAsB,EAAE,KAAsB;CAC5E,MAAM,gBACJ,eAAe,sBAAsB,iBACrC,cAAc,qBAAqB;CACrC,MAAM,mBACJ,eAAe,sBAAsB,WACrC,cAAc,qBAAqB;CAGrC,MAAM,eAAe,qBAAqB;EACxC,WAAW,IAAI;EACf,WAAW,IAAI;EAChB,CAAC;AAEF,KAAI,aACF,QAAO;CAIT,MAAM,uBAAuB,IAAI,YAAY,kBAAkB;AAE/D,KAAI,CAAC,qBACH,QAAO;CAQT,MAAM,qBAAqB,eALI,sBAC7B,sBACA,iBACD,EAIC,kBACA,cACD;AAED,KAAI,mBACF,QAAO;AAIT,QAAO"}
|
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { DefaultValues } from "@intlayer/config/client";
|
|
3
3
|
import configuration from "@intlayer/config/built";
|
|
4
4
|
|
|
5
5
|
//#region src/localization/getLocaleFromPath.ts
|
|
6
6
|
/**
|
|
7
|
-
* Extracts the locale segment from the given URL or pathname
|
|
8
|
-
* If no locale is present, returns the default locale (en).
|
|
7
|
+
* Extracts the locale segment from the given URL or pathname based on the routing mode.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* getLocaleFromPath('/dashboard') // Returns 'en'
|
|
16
|
-
* getLocaleFromPath('dashboard') // Returns 'en'
|
|
17
|
-
* getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'
|
|
18
|
-
* getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'
|
|
19
|
-
* getLocaleFromPath('https://example.com/dashboard') // Returns 'en'
|
|
20
|
-
* ```
|
|
9
|
+
* Mode Behaviors:
|
|
10
|
+
* - 'prefix-no-default': Checks path prefiIf no prefix found, assumes default locale.
|
|
11
|
+
* - 'prefix-all': Checks path prefix.
|
|
12
|
+
* - 'search-params': Checks for 'locale' query parameter.
|
|
13
|
+
* - 'no-prefix': Returns undefined (or default if fallback is true).
|
|
21
14
|
*
|
|
22
15
|
* @param inputUrl - The complete URL string or pathname to process.
|
|
23
|
-
* @returns The detected locale
|
|
16
|
+
* @returns The detected locale, default locale (if fallback/implicit), or undefined.
|
|
24
17
|
*/
|
|
25
|
-
const getLocaleFromPath = (inputUrl = "/") => {
|
|
26
|
-
const { defaultLocale, locales } =
|
|
27
|
-
|
|
18
|
+
const getLocaleFromPath = (inputUrl = "/", options) => {
|
|
19
|
+
const { defaultLocale, locales, mode } = {
|
|
20
|
+
defaultLocale: configuration?.internationalization?.defaultLocale ?? DefaultValues.Internationalization.DEFAULT_LOCALE,
|
|
21
|
+
mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,
|
|
22
|
+
locales: configuration?.internationalization?.locales ?? DefaultValues.Internationalization.LOCALES,
|
|
23
|
+
...options
|
|
24
|
+
};
|
|
25
|
+
if (!defaultLocale || !locales) return DefaultValues.Internationalization.DEFAULT_LOCALE;
|
|
28
26
|
const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);
|
|
29
27
|
let fixedInputUrl = inputUrl;
|
|
30
|
-
if (inputUrl?.endsWith("/")) fixedInputUrl = inputUrl.slice(0, -1);
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
|
|
28
|
+
if (inputUrl?.endsWith("/") && inputUrl.length > 1) fixedInputUrl = inputUrl.slice(0, -1);
|
|
29
|
+
const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
|
|
30
|
+
if (mode === "search-params") {
|
|
31
|
+
const localeParam = url.searchParams.get("locale");
|
|
32
|
+
if (localeParam && locales.includes(localeParam)) return localeParam;
|
|
33
|
+
return defaultLocale;
|
|
34
|
+
}
|
|
35
|
+
if (mode === "no-prefix") return defaultLocale;
|
|
36
|
+
const firstSegment = url.pathname.split("/")[1];
|
|
34
37
|
if (firstSegment && locales.includes(firstSegment)) return firstSegment;
|
|
35
|
-
return defaultLocale;
|
|
38
|
+
if (mode === "prefix-no-default") return defaultLocale;
|
|
36
39
|
};
|
|
37
40
|
|
|
38
41
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromPath.mjs","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locale,
|
|
1
|
+
{"version":3,"file":"getLocaleFromPath.mjs","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { Locale, LocalesValues, RoutingConfig } from '@intlayer/types';\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 ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\n ...options,\n };\n\n if (!defaultLocale || !locales) {\n return DefaultValues.Internationalization.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":";;;;;;;;;;;;;;;;;AAuBA,MAAa,qBACX,WAAmB,KACnB,YACuB;CACvB,MAAM,EAAE,eAAe,SAAS,SAAS;EACvC,eACE,eAAe,sBAAsB,iBACrC,cAAc,qBAAqB;EACrC,MAAM,eAAe,SAAS,QAAQ,cAAc,QAAQ;EAC5D,SACE,eAAe,sBAAsB,WACrC,cAAc,qBAAqB;EACrC,GAAG;EACJ;AAED,KAAI,CAAC,iBAAiB,CAAC,QACrB,QAAO,cAAc,qBAAqB;CAI5C,MAAM,gBAAgB,mBAAmB,SAAS;CAClD,IAAI,gBAAgB;AAEpB,KAAI,UAAU,SAAS,IAAI,IAAI,SAAS,SAAS,EAC/C,iBAAgB,SAAS,MAAM,GAAG,GAAG;CAIvC,MAAM,MAAM,gBACR,IAAI,IAAI,cAAc,GACtB,IAAI,IAAI,eAAe,qBAAqB;AAIhD,KAAI,SAAS,iBAAiB;EAC5B,MAAM,cAAc,IAAI,aAAa,IAAI,SAAS;AAElD,MAAI,eAAe,QAAQ,SAAS,YAAY,CAC9C,QAAO;AAGT,SAAO;;AAKT,KAAI,SAAS,YACX,QAAO;CAST,MAAM,eALW,IAAI,SAIS,MAAM,IAAI,CACN;AAKlC,KAFwB,gBAAgB,QAAQ,SAAS,aAAa,CAGpE,QAAO;AAIT,KAAI,SAAS,oBAEX,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedUrl.mjs","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\nimport { getPrefix } from './getPrefix';\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,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: '
|
|
1
|
+
{"version":3,"file":"getLocalizedUrl.mjs","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues, RoutingConfig } from '@intlayer/types';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\nimport { getPrefix } from './getPrefix';\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,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n } = {}\n): string => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\n ...options,\n };\n\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n if (mode === 'no-prefix') {\n // No locale prefixing\n return urlWithoutLocale;\n }\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n if (mode === 'search-params') {\n // Use search parameters for locale handling\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', currentLocale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${parsedUrl.pathname}?${queryString}`\n : parsedUrl.pathname;\n\n if (isAbsoluteUrl) {\n return `${baseUrl}${pathWithQuery}${parsedUrl.hash}`;\n }\n\n return `${pathWithQuery}${parsedUrl.hash}`;\n }\n\n const { prefix } = getPrefix(currentLocale, {\n defaultLocale,\n mode,\n locales,\n });\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = `/${prefix}${parsedUrl.pathname}`;\n\n // Remove double slashes\n localizedPath = localizedPath.replaceAll(/\\/+/g, '/');\n\n // Remove trailing slash for non-root paths\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n if (isAbsoluteUrl) {\n return `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n return `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,mBACX,KACA,eACA,UAII,EAAE,KACK;CACX,MAAM,EAAE,eAAe,MAAM,YAAY;EACvC,eACE,eAAe,sBAAsB,iBACrC,cAAc,qBAAqB;EACrC,MAAM,eAAe,SAAS,QAAQ,cAAc,QAAQ;EAC5D,SACE,eAAe,sBAAsB,WACrC,cAAc,qBAAqB;EACrC,GAAG;EACJ;CAGD,MAAM,mBAAmB,qBAAqB,KAAK,QAAQ;AAE3D,KAAI,SAAS,YAEX,QAAO;CAIT,MAAM,gBAAgB,mBAAmB,iBAAiB;CAI1D,MAAM,YAAY,gBACd,IAAI,IAAI,iBAAiB,GACzB,IAAI,IAAI,kBAAkB,qBAAqB;CAGnD,MAAM,UAAU,gBACZ,GAAG,UAAU,SAAS,IAAI,UAAU,SACpC;AAEJ,KAAI,SAAS,iBAAiB;EAE5B,MAAM,eAAe,IAAI,gBAAgB,UAAU,OAAO;AAC1D,eAAa,IAAI,UAAU,cAAc,UAAU,CAAC;EAEpD,MAAM,cAAc,aAAa,UAAU;EAC3C,MAAM,gBAAgB,cAClB,GAAG,UAAU,SAAS,GAAG,gBACzB,UAAU;AAEd,MAAI,cACF,QAAO,GAAG,UAAU,gBAAgB,UAAU;AAGhD,SAAO,GAAG,gBAAgB,UAAU;;CAGtC,MAAM,EAAE,WAAW,UAAU,eAAe;EAC1C;EACA;EACA;EACD,CAAC;CAGF,IAAI,gBAAgB,IAAI,SAAS,UAAU;AAG3C,iBAAgB,cAAc,WAAW,QAAQ,IAAI;AAGrD,KAAI,cAAc,SAAS,KAAK,cAAc,SAAS,IAAI,CACzD,iBAAgB,cAAc,MAAM,GAAG,GAAG;AAI5C,KAAI,cACF,QAAO,GAAG,UAAU,gBAAgB,UAAU,SAAS,UAAU;AAGnE,QAAO,GAAG,gBAAgB,UAAU,SAAS,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualUrls.mjs","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type {
|
|
1
|
+
{"version":3,"file":"getMultilingualUrls.mjs","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type {\n LocalesValues,\n RoutingConfig,\n StrictModeLocaleMap,\n} from '@intlayer/types';\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 } = {}\n): StrictModeLocaleMap<string> => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\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 });\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,uBACX,KACA,UAII,EAAE,KAC0B;CAChC,MAAM,EAAE,eAAe,MAAM,YAAY;EACvC,eACE,eAAe,sBAAsB,iBACrC,cAAc,qBAAqB;EACrC,MAAM,eAAe,SAAS,QAAQ,cAAc,QAAQ;EAC5D,SACE,eAAe,sBAAsB,WACrC,cAAc,qBAAqB;EACrC,GAAG;EACJ;AAoBD,SAjB0B,WAAW,EAAE,EAAE,QACtC,KAAK,WAAW;AASf,MAAI,UAPiB,gBAAgB,KAAK,QAAQ;GAChD;GACA;GACA;GACD,CAAC;AAKF,SAAO;IAET,EAAE,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrefix.mjs","names":[],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { Locale, LocalesValues } from '@intlayer/types';\n\nexport type GetPrefixOptions = {\n defaultLocale?: LocalesValues;\n mode?: '
|
|
1
|
+
{"version":3,"file":"getPrefix.mjs","names":[],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { Locale, LocalesValues, RoutingConfig } from '@intlayer/types';\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 ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAa,aACX,QACA,UAII,EAAE,KACc;CACpB,MAAM,EAAE,eAAe,MAAM,YAAY;EACvC,eACE,eAAe,sBAAsB,iBACrC,cAAc,qBAAqB;EACrC,MAAM,eAAe,SAAS,QAAQ,cAAc,QAAQ;EAC5D,SACE,eAAe,sBAAsB,WACrC,cAAc,qBAAqB;EACrC,GAAG;EACJ;AAED,KAAI,CAAC,UAAU,CAAC,QAAQ,SAAS,OAAO,CACtC,QAAO;EACL,QAAQ;EACR,cAAc;EACf;AAQH,KAHE,SAAS,gBACR,SAAS,uBAAuB,kBAAkB,OAGnD,QAAO;EACL,QAAQ,GAAG,OAAO;EAClB,cAAc;EACf;AAGH,QAAO;EACL,QAAQ;EACR,cAAc;EACf"}
|
package/dist/esm/utils/intl.mjs
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
1
|
import { Locales } from "@intlayer/types";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/intl.ts
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Optimized Cache Key Generator
|
|
6
|
+
* 1. Fast path: If no options, just use the locale string.
|
|
7
|
+
* 2. Normal path: JSON.stringify for deterministic object comparison.
|
|
8
|
+
*/
|
|
9
|
+
const getCacheKey = (locales, options) => {
|
|
10
|
+
const localeKey = locales ? String(locales) : Locales.ENGLISH;
|
|
11
|
+
if (!options) return localeKey;
|
|
12
|
+
return `${localeKey}|${JSON.stringify(options)}`;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Generic wrapper for any `new Intl.*()` constructor.
|
|
16
|
+
*/
|
|
5
17
|
const createCachedConstructor = (Ctor) => {
|
|
6
18
|
const cache = /* @__PURE__ */ new Map();
|
|
19
|
+
const MAX_CACHE_SIZE = 50;
|
|
7
20
|
function Wrapped(locales, options) {
|
|
8
|
-
if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function")
|
|
9
|
-
|
|
10
|
-
const message = [
|
|
11
|
-
`// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,
|
|
12
|
-
`// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,
|
|
13
|
-
``,
|
|
14
|
-
`import 'intl';`,
|
|
15
|
-
`import '@formatjs/intl-displaynames/polyfill';`,
|
|
16
|
-
`import '@formatjs/intl-getcanonicallocales/polyfill';`,
|
|
17
|
-
`import '@formatjs/intl-locale/polyfill';`,
|
|
18
|
-
`import '@formatjs/intl-pluralrules/polyfill';`,
|
|
19
|
-
`import '@formatjs/intl-listformat/polyfill';`,
|
|
20
|
-
`import '@formatjs/intl-numberformat/polyfill';`,
|
|
21
|
-
`import '@formatjs/intl-relativetimeformat/polyfill';`,
|
|
22
|
-
`import '@formatjs/intl-datetimeformat/polyfill';`,
|
|
23
|
-
``,
|
|
24
|
-
`// Optionally add locale data`,
|
|
25
|
-
`import '@formatjs/intl-pluralrules/locale-data/fr';`,
|
|
26
|
-
`import '@formatjs/intl-numberformat/locale-data/fr';`,
|
|
27
|
-
`import '@formatjs/intl-datetimeformat/locale-data/fr';`
|
|
28
|
-
].join("\n");
|
|
29
|
-
console.warn(message);
|
|
30
|
-
throw new Error(message);
|
|
31
|
-
}
|
|
32
|
-
return locales;
|
|
33
|
-
}
|
|
34
|
-
const key = cacheKey(locales ?? Locales.ENGLISH, options);
|
|
21
|
+
if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function") return locales;
|
|
22
|
+
const key = getCacheKey(locales, options);
|
|
35
23
|
let instance = cache.get(key);
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
if (instance) return instance;
|
|
25
|
+
instance = new Ctor(locales, options);
|
|
26
|
+
if (cache.size >= MAX_CACHE_SIZE) {
|
|
27
|
+
const oldestKey = cache.keys().next().value;
|
|
28
|
+
if (oldestKey) cache.delete(oldestKey);
|
|
39
29
|
}
|
|
30
|
+
cache.set(key, instance);
|
|
40
31
|
return instance;
|
|
41
32
|
}
|
|
42
33
|
Wrapped.prototype = Ctor.prototype;
|
|
43
34
|
return Wrapped;
|
|
44
35
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Factory that turns the global `Intl` into a cached clone.
|
|
38
|
+
*/
|
|
39
|
+
const createCachedIntl = () => {
|
|
40
|
+
const constructorCache = /* @__PURE__ */ new Map();
|
|
41
|
+
return new Proxy(Intl, { get: (target, prop, receiver) => {
|
|
42
|
+
if (constructorCache.has(prop)) return constructorCache.get(prop);
|
|
43
|
+
const value = Reflect.get(target, prop, receiver);
|
|
44
|
+
if (typeof value === "function" && typeof prop === "string" && /^[A-Z]/.test(prop)) {
|
|
45
|
+
const wrapped = createCachedConstructor(value);
|
|
46
|
+
constructorCache.set(prop, wrapped);
|
|
47
|
+
return wrapped;
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
} });
|
|
51
|
+
};
|
|
49
52
|
const CachedIntl = createCachedIntl();
|
|
50
53
|
|
|
51
54
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.mjs","names":[
|
|
1
|
+
{"version":3,"file":"intl.mjs","names":[],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// ... (Keep your Type Helper definitions here: IntlConstructors, ReplaceLocaleWithLocalesValues, WrappedIntl) ...\n\n/**\n * Optimized Cache Key Generator\n * 1. Fast path: If no options, just use the locale string.\n * 2. Normal path: JSON.stringify for deterministic object comparison.\n */\nconst getCacheKey = (\n locales: LocalesValues | undefined,\n options: unknown\n): string => {\n const localeKey = locales ? String(locales) : Locales.ENGLISH;\n\n if (!options) return localeKey;\n\n // JSON.stringify is the most robust way to handle nested options objects\n // without a heavy custom hashing function.\n return `${localeKey}|${JSON.stringify(options)}`;\n};\n\n/**\n * Generic wrapper for any `new Intl.*()` constructor.\n */\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n // The cache lives here, inside the closure of the wrapped constructor.\n const cache = new Map<string, InstanceType<T>>();\n const MAX_CACHE_SIZE = 50;\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // 1. Handle DisplayNames Polyfill warning (Keep your existing logic here)\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n // ... (Your existing polyfill warning logic) ...\n return locales as any;\n }\n\n // 2. Generate Key\n const key = getCacheKey(locales, options);\n\n // 3. Check Cache\n let instance = cache.get(key);\n if (instance) return instance;\n\n // 4. Create New Instance\n instance = new Ctor(locales as never, options as never);\n\n // 5. Smart Eviction (LRU-ish)\n // Map iterates in insertion order. Deleting the first key removes the \"oldest\".\n if (cache.size >= MAX_CACHE_SIZE) {\n const oldestKey = cache.keys().next().value;\n if (oldestKey) cache.delete(oldestKey);\n }\n\n cache.set(key, instance as InstanceType<T>);\n return instance as InstanceType<T>;\n }\n\n // Preserve prototype for `instanceof` checks\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n/**\n * Factory that turns the global `Intl` into a cached clone.\n */\nexport const createCachedIntl = (): WrappedIntl => {\n // 🔥 CRITICAL OPTIMIZATION:\n // We must cache the *wrapped constructors* themselves.\n // Otherwise, the Proxy creates a new `Wrapped` function (and a new empty Map)\n // on every single property access.\n const constructorCache = new Map<string | symbol, any>();\n\n return new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n // 1. Fast return if we already wrapped this constructor\n if (constructorCache.has(prop)) {\n return constructorCache.get(prop);\n }\n\n const value = Reflect.get(target, prop, receiver);\n\n // 2. Wrap only Constructors (Heuristic: Function + starts with Uppercase)\n // This prevents wrapping static methods like `Intl.getCanonicalLocales`\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n const wrapped = createCachedConstructor(value);\n constructorCache.set(prop, wrapped);\n return wrapped;\n }\n\n // 3. Pass through everything else (static methods, constants)\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\nexport const CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\nexport { CachedIntl as Intl };\n"],"mappings":";;;;;;;;AAoEA,MAAM,eACJ,SACA,YACW;CACX,MAAM,YAAY,UAAU,OAAO,QAAQ,GAAG,QAAQ;AAEtD,KAAI,CAAC,QAAS,QAAO;AAIrB,QAAO,GAAG,UAAU,GAAG,KAAK,UAAU,QAAQ;;;;;AAMhD,MAAM,2BACJ,SACG;CAEH,MAAM,wBAAQ,IAAI,KAA8B;CAChD,MAAM,iBAAiB;CAEvB,SAAS,QAAQ,SAAyB,SAAe;AAEvD,MACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,WAGvC,QAAO;EAIT,MAAM,MAAM,YAAY,SAAS,QAAQ;EAGzC,IAAI,WAAW,MAAM,IAAI,IAAI;AAC7B,MAAI,SAAU,QAAO;AAGrB,aAAW,IAAI,KAAK,SAAkB,QAAiB;AAIvD,MAAI,MAAM,QAAQ,gBAAgB;GAChC,MAAM,YAAY,MAAM,MAAM,CAAC,MAAM,CAAC;AACtC,OAAI,UAAW,OAAM,OAAO,UAAU;;AAGxC,QAAM,IAAI,KAAK,SAA4B;AAC3C,SAAO;;AAIT,CAAC,QAAgB,YAAa,KAAa;AAE3C,QAAO;;;;;AAMT,MAAa,yBAAsC;CAKjD,MAAM,mCAAmB,IAAI,KAA2B;AAExD,QAAO,IAAI,MAAM,MAA0B,EACzC,MAAM,QAAQ,MAAM,aAAa;AAE/B,MAAI,iBAAiB,IAAI,KAAK,CAC5B,QAAO,iBAAiB,IAAI,KAAK;EAGnC,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAIjD,MACE,OAAO,UAAU,cACjB,OAAO,SAAS,YAChB,SAAS,KAAK,KAAK,EACnB;GACA,MAAM,UAAU,wBAAwB,MAAM;AAC9C,oBAAiB,IAAI,MAAM,QAAQ;AACnC,UAAO;;AAIT,SAAO;IAEV,CAAC;;AAGJ,MAAa,aAAa,kBAAkB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeProps, Plugins } from "../interpreter/getContent/plugins.js";
|
|
2
2
|
import "../interpreter/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _intlayer_types6 from "@intlayer/types";
|
|
4
4
|
import { ContentNode, DeclaredLocales, Dictionary, LocalesValues } from "@intlayer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts
|
|
@@ -24,12 +24,12 @@ declare const getFilterMissingTranslationsContent: <T extends ContentNode, L ext
|
|
|
24
24
|
declare const getFilterMissingTranslationsDictionary: (dictionary: Dictionary, localeToCheck: LocalesValues) => {
|
|
25
25
|
content: any;
|
|
26
26
|
$schema?: string;
|
|
27
|
-
id?:
|
|
27
|
+
id?: _intlayer_types6.DictionaryId;
|
|
28
28
|
projectIds?: string[];
|
|
29
|
-
localId?:
|
|
30
|
-
localIds?:
|
|
31
|
-
format?:
|
|
32
|
-
key:
|
|
29
|
+
localId?: _intlayer_types6.LocalDictionaryId;
|
|
30
|
+
localIds?: _intlayer_types6.LocalDictionaryId[];
|
|
31
|
+
format?: _intlayer_types6.DictionaryFormat;
|
|
32
|
+
key: _intlayer_types6.DictionaryKey;
|
|
33
33
|
title?: string;
|
|
34
34
|
description?: string;
|
|
35
35
|
versions?: string[];
|
|
@@ -37,11 +37,11 @@ declare const getFilterMissingTranslationsDictionary: (dictionary: Dictionary, l
|
|
|
37
37
|
filePath?: string;
|
|
38
38
|
tags?: string[];
|
|
39
39
|
locale?: LocalesValues;
|
|
40
|
-
fill?:
|
|
40
|
+
fill?: _intlayer_types6.Fill;
|
|
41
41
|
filled?: true;
|
|
42
42
|
priority?: number;
|
|
43
43
|
live?: boolean;
|
|
44
|
-
location?:
|
|
44
|
+
location?: _intlayer_types6.DictionaryLocation;
|
|
45
45
|
};
|
|
46
46
|
//#endregion
|
|
47
47
|
export { filterMissingTranslationsOnlyPlugin, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilterMissingTranslationsContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":[],"mappings":";;;;;;;cAmMa,qDACI,kBACd;;AAFH;AA8LA;;;;;;;;AA0BA;;;;cA1Ba,gDACD,uBACA,gBAAgB,uBAEpB,kBACS,cACJ;cAoBA,qDACC,2BACG;;;OAAa,
|
|
1
|
+
{"version":3,"file":"getFilterMissingTranslationsContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":[],"mappings":";;;;;;;cAmMa,qDACI,kBACd;;AAFH;AA8LA;;;;;;;;AA0BA;;;;cA1Ba,gDACD,uBACA,gBAAgB,uBAEpB,kBACS,cACJ;cAoBA,qDACC,2BACG;;;OAAa,gBAAA,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepTransformContent, NodeProps, Plugins } from "../interpreter/getContent/plugins.js";
|
|
2
2
|
import "../interpreter/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _intlayer_types0 from "@intlayer/types";
|
|
4
4
|
import { ContentNode, DeclaredLocales, Dictionary, LocalesValues } from "@intlayer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts
|
|
@@ -16,12 +16,12 @@ declare const getFilterTranslationsOnlyContent: <T extends ContentNode, L extend
|
|
|
16
16
|
declare const getFilterTranslationsOnlyDictionary: (dictionary: Dictionary, locale?: LocalesValues, fallback?: LocalesValues) => {
|
|
17
17
|
content: any;
|
|
18
18
|
$schema?: string;
|
|
19
|
-
id?:
|
|
19
|
+
id?: _intlayer_types0.DictionaryId;
|
|
20
20
|
projectIds?: string[];
|
|
21
|
-
localId?:
|
|
22
|
-
localIds?:
|
|
23
|
-
format?:
|
|
24
|
-
key:
|
|
21
|
+
localId?: _intlayer_types0.LocalDictionaryId;
|
|
22
|
+
localIds?: _intlayer_types0.LocalDictionaryId[];
|
|
23
|
+
format?: _intlayer_types0.DictionaryFormat;
|
|
24
|
+
key: _intlayer_types0.DictionaryKey;
|
|
25
25
|
title?: string;
|
|
26
26
|
description?: string;
|
|
27
27
|
versions?: string[];
|
|
@@ -29,11 +29,11 @@ declare const getFilterTranslationsOnlyDictionary: (dictionary: Dictionary, loca
|
|
|
29
29
|
filePath?: string;
|
|
30
30
|
tags?: string[];
|
|
31
31
|
locale?: LocalesValues;
|
|
32
|
-
fill?:
|
|
32
|
+
fill?: _intlayer_types0.Fill;
|
|
33
33
|
filled?: true;
|
|
34
34
|
priority?: number;
|
|
35
35
|
live?: boolean;
|
|
36
|
-
location?:
|
|
36
|
+
location?: _intlayer_types0.DictionaryLocation;
|
|
37
37
|
};
|
|
38
38
|
//#endregion
|
|
39
39
|
export { filterTranslationsOnlyPlugin, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeProps } from "../interpreter/getContent/plugins.js";
|
|
2
2
|
import "../interpreter/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _intlayer_types13 from "@intlayer/types";
|
|
4
4
|
import { ContentNode, Dictionary, LocalesValues } from "@intlayer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/deepTransformPlugins/getFilteredLocalesContent.d.ts
|
|
@@ -8,12 +8,12 @@ declare const getFilteredLocalesContent: (node: ContentNode, locales: LocalesVal
|
|
|
8
8
|
declare const getFilteredLocalesDictionary: (dictionary: Dictionary, locale: LocalesValues | LocalesValues[]) => {
|
|
9
9
|
content: any;
|
|
10
10
|
$schema?: string;
|
|
11
|
-
id?:
|
|
11
|
+
id?: _intlayer_types13.DictionaryId;
|
|
12
12
|
projectIds?: string[];
|
|
13
|
-
localId?:
|
|
14
|
-
localIds?:
|
|
15
|
-
format?:
|
|
16
|
-
key:
|
|
13
|
+
localId?: _intlayer_types13.LocalDictionaryId;
|
|
14
|
+
localIds?: _intlayer_types13.LocalDictionaryId[];
|
|
15
|
+
format?: _intlayer_types13.DictionaryFormat;
|
|
16
|
+
key: _intlayer_types13.DictionaryKey;
|
|
17
17
|
title?: string;
|
|
18
18
|
description?: string;
|
|
19
19
|
versions?: string[];
|
|
@@ -21,11 +21,11 @@ declare const getFilteredLocalesDictionary: (dictionary: Dictionary, locale: Loc
|
|
|
21
21
|
filePath?: string;
|
|
22
22
|
tags?: string[];
|
|
23
23
|
locale?: LocalesValues;
|
|
24
|
-
fill?:
|
|
24
|
+
fill?: _intlayer_types13.Fill;
|
|
25
25
|
filled?: true;
|
|
26
26
|
priority?: number;
|
|
27
27
|
live?: boolean;
|
|
28
|
-
location?:
|
|
28
|
+
location?: _intlayer_types13.DictionaryLocation;
|
|
29
29
|
};
|
|
30
30
|
//#endregion
|
|
31
31
|
export { getFilteredLocalesContent, getFilteredLocalesDictionary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilteredLocalesContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":[],"mappings":";;;;;;cAsCa,kCACL,sBACG,gBAAgB,4BACd;cAwBA,2CACC,oBACJ,gBAAgB;;;EA7Bb,EAAA,CAAA,EA6B0B,
|
|
1
|
+
{"version":3,"file":"getFilteredLocalesContent.d.ts","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":[],"mappings":";;;;;;cAsCa,kCACL,sBACG,gBAAgB,4BACd;cAwBA,2CACC,oBACJ,gBAAgB;;;EA7Bb,EAAA,CAAA,EA6B0B,iBAAA,CAAA,YAbtC;EAfO,UAAA,CAAA,EAAA,MAAA,EAAA;EACG,OAAA,CAAA,qCAAA;EAAgB,QAAA,CAAA,uCAAA;EACd,MAAA,CAAA,oCAAA;EAAS,GAAA,iCAAA;EAwBT,KAAA,CAAA,EAAA,MAAA;EACC,WAAA,CAAA,EAAA,MAAA;EACJ,QAAA,CAAA,EAAA,MAAA,EAAA;EAAgB,OAAA,CAAA,EAAA,MAAA;EAAa,QAAA,CAAA,EAAA,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContent.d.ts","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"getContent.d.ts","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;;AAIQ,cAJK,UAIL,EAAA,CAAA,UAHI,WAGJ,EAAA,UAFI,aAEJ,GAFoB,eAEpB,CAAA,CAAA,IAAA,EAAA,CAAA,EAAA,SAAA,EACK,SADL,EAAA,MAAA,CAAA,EAEG,CAFH,EAAA,GAmBA,oBAnBA,CAmBqB,CAnBrB,EAmBwB,uBAnBxB,EAmBiD,CAnBjD,CAAA"}
|
|
@@ -76,7 +76,7 @@ type NestedCond<T, S, L> = T extends {
|
|
|
76
76
|
path?: infer P;
|
|
77
77
|
} ? GetNestingResult<K, P, S> : never : never;
|
|
78
78
|
/** Nested plugin. Replaces node with the result of `getNesting`. */
|
|
79
|
-
declare const nestedPlugin: Plugins;
|
|
79
|
+
declare const nestedPlugin: (locale?: LocalesValues) => Plugins;
|
|
80
80
|
type FileCond<T> = T extends {
|
|
81
81
|
nodeType: NodeType | string;
|
|
82
82
|
[NodeType.File]: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAoCA;AAcA;;;;;;AAIc,KAlBF,OAAA,GAkBE;EACR,EAAA,EAAA,MAAA;EAAgB,SAAA,EAAA,CAAA,IAAA,EAAA,GAAA,EAAA,GAAA,OAAA;EACO,SAAA,EAAA,CAAA,IAAA,EAAA,GAAA,EAAA,KAAA,EAflB,SAekB,EAAA,WAAA,EAAA,CAAA,IAAA,EAAA,GAAA,EAAA,KAAA,EAdO,SAcP,EAAA,GAAA,GAAA,EAAA,GAAA,GAAA;CAAE;;;;AACM,KAPzB,eAOyB,CAAA,CAAA,EAAA,CAAA,EAAA,UAPO,aAOP,CAAA,GAPwB,CAOxB,SAAA;EAAI,QAAA,EAN7B,QAM6B,GAAA,MAAA;EAAjC,CALL,QAAA,CAAS,WAAA,CAKJ,EAAA,KAAA,EAAA;CAAoB,GAAA,CAAA,SAHd,MAGc,CAHP,WAGO,EAAA,OAAA,CAAA,GAFtB,CAEsB,SAAA,MAFN,CAEM,GADpB,oBACoB,CADC,CACD,CADG,CACH,CAAA,EADO,CACP,CAAA,GAApB,oBAAoB,CAAC,CAAD,CAAA,MAAS,CAAT,CAAA,EAAa,CAAb,CAAA,GAAA,KAAA,GAAA,KAAA;AAK5B;AACU,cADG,iBACH,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esValues, RoutingConfig } from "@intlayer/types";
|
|
2
2
|
|
|
3
3
|
//#region src/localization/getLocaleFromPath.d.ts
|
|
4
|
-
|
|
4
|
+
type GetLocaleFromPathOptions = {
|
|
5
|
+
defaultLocale?: LocalesValues;
|
|
6
|
+
locales?: LocalesValues[];
|
|
7
|
+
mode?: RoutingConfig['mode'];
|
|
8
|
+
};
|
|
5
9
|
/**
|
|
6
|
-
* Extracts the locale segment from the given URL or pathname
|
|
7
|
-
* If no locale is present, returns the default locale (en).
|
|
8
|
-
*
|
|
9
|
-
* Example:
|
|
10
|
+
* Extracts the locale segment from the given URL or pathname based on the routing mode.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'
|
|
17
|
-
* getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'
|
|
18
|
-
* getLocaleFromPath('https://example.com/dashboard') // Returns 'en'
|
|
19
|
-
* ```
|
|
12
|
+
* Mode Behaviors:
|
|
13
|
+
* - 'prefix-no-default': Checks path prefiIf no prefix found, assumes default locale.
|
|
14
|
+
* - 'prefix-all': Checks path prefix.
|
|
15
|
+
* - 'search-params': Checks for 'locale' query parameter.
|
|
16
|
+
* - 'no-prefix': Returns undefined (or default if fallback is true).
|
|
20
17
|
*
|
|
21
18
|
* @param inputUrl - The complete URL string or pathname to process.
|
|
22
|
-
* @returns The detected locale
|
|
19
|
+
* @returns The detected locale, default locale (if fallback/implicit), or undefined.
|
|
23
20
|
*/
|
|
24
|
-
declare const getLocaleFromPath: (inputUrl?: string) => Locale;
|
|
21
|
+
declare const getLocaleFromPath: (inputUrl?: string, options?: GetLocaleFromPathOptions) => Locale | undefined;
|
|
25
22
|
//#endregion
|
|
26
23
|
export { getLocaleFromPath };
|
|
27
24
|
//# sourceMappingURL=getLocaleFromPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromPath.d.ts","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getLocaleFromPath.d.ts","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":[],"mappings":";;;KAKK,wBAAA;kBACa;EADb,OAAA,CAAA,EAEO,aAFP,EAAA;EACa,IAAA,CAAA,EAET,aAFS,CAAA,MAAA,CAAA;CACN;;;AAgBZ;;;;;;;;;;cAAa,iDAED,6BACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LocalesValues } from "@intlayer/types";
|
|
1
|
+
import { LocalesValues, RoutingConfig } from "@intlayer/types";
|
|
2
2
|
|
|
3
3
|
//#region src/localization/getLocalizedUrl.d.ts
|
|
4
4
|
|
|
@@ -41,7 +41,7 @@ import { LocalesValues } from "@intlayer/types";
|
|
|
41
41
|
declare const getLocalizedUrl: (url: string, currentLocale: LocalesValues, options?: {
|
|
42
42
|
locales?: LocalesValues[];
|
|
43
43
|
defaultLocale?: LocalesValues;
|
|
44
|
-
mode?: "
|
|
44
|
+
mode?: RoutingConfig["mode"];
|
|
45
45
|
}) => string;
|
|
46
46
|
//#endregion
|
|
47
47
|
export { getLocalizedUrl };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedUrl.d.ts","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":[],"mappings":";;;;;;AA2CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,8CAEI;YAEH;kBACM"}
|
|
1
|
+
{"version":3,"file":"getLocalizedUrl.d.ts","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":[],"mappings":";;;;;;AA2CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,8CAEI;YAEH;kBACM;SACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LocalesValues, StrictModeLocaleMap } from "@intlayer/types";
|
|
1
|
+
import { LocalesValues, RoutingConfig, StrictModeLocaleMap } from "@intlayer/types";
|
|
2
2
|
|
|
3
3
|
//#region src/localization/getMultilingualUrls.d.ts
|
|
4
4
|
|
|
@@ -39,7 +39,7 @@ import { LocalesValues, StrictModeLocaleMap } from "@intlayer/types";
|
|
|
39
39
|
declare const getMultilingualUrls: (url: string, options?: {
|
|
40
40
|
locales?: LocalesValues[];
|
|
41
41
|
defaultLocale?: LocalesValues;
|
|
42
|
-
mode?: "
|
|
42
|
+
mode?: RoutingConfig["mode"];
|
|
43
43
|
}) => StrictModeLocaleMap<string>;
|
|
44
44
|
//#endregion
|
|
45
45
|
export { getMultilingualUrls };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualUrls.d.ts","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"getMultilingualUrls.d.ts","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":[],"mappings":";;;;;;AA2CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa;YAGC;kBACM;SACT;MAER"}
|