@intlayer/core 8.6.2 → 8.6.4
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/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +1 -2
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +2 -3
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +2 -3
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +1 -2
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs +2 -4
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
- package/dist/cjs/formatters/compact.cjs +1 -2
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs +1 -2
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs +1 -2
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/list.cjs +1 -2
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs +1 -2
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs +1 -2
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs +1 -2
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs +1 -2
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +2 -3
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +35 -7
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs +1 -2
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs +4 -8
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +2 -3
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +11 -5
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs +12 -5
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs +13 -13
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +3 -4
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs +1 -2
- package/dist/cjs/localization/localeResolver.cjs.map +1 -1
- package/dist/cjs/localization/rewriteUtils.cjs +9 -6
- package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
- package/dist/cjs/localization/validatePrefix.cjs +9 -3
- package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +1 -2
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs +43 -35
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs +2 -2
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs +3 -3
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs +3 -3
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs +2 -2
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs +2 -3
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
- package/dist/esm/formatters/compact.mjs +2 -2
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs +2 -2
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs +2 -2
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/list.mjs +2 -2
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs +2 -2
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs +2 -2
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs +2 -2
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs +2 -2
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs +3 -3
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +35 -7
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs +2 -2
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/localization/getBrowserLocale.mjs +1 -4
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs +3 -3
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +10 -3
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs +11 -3
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs +13 -12
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/localization/localeMapper.mjs +4 -4
- package/dist/esm/localization/localeMapper.mjs.map +1 -1
- package/dist/esm/localization/localeResolver.mjs +2 -2
- package/dist/esm/localization/localeResolver.mjs.map +1 -1
- package/dist/esm/localization/rewriteUtils.mjs +5 -2
- package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
- package/dist/esm/localization/validatePrefix.mjs +8 -1
- package/dist/esm/localization/validatePrefix.mjs.map +1 -1
- package/dist/esm/utils/intl.mjs +2 -2
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs +35 -26
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +1 -2
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
- package/dist/types/localization/getPrefix.d.ts.map +1 -1
- package/dist/types/localization/localeResolver.d.ts.map +1 -1
- package/dist/types/localization/rewriteUtils.d.ts.map +1 -1
- package/dist/types/localization/validatePrefix.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/dist/types/utils/localeStorage.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
5
|
-
let _intlayer_config_envVars = require("@intlayer/config/envVars");
|
|
6
4
|
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
7
5
|
|
|
8
6
|
//#region src/localization/getPrefix.ts
|
|
9
7
|
/**
|
|
8
|
+
* True when the build-time routing mode is known and is not a prefix-based
|
|
9
|
+
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
10
|
+
*/
|
|
11
|
+
const TREE_SHAKE_PREFIX_MODES = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all" && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-no-default";
|
|
12
|
+
/**
|
|
10
13
|
* Resolves routing configuration by merging provided options with configuration defaults.
|
|
11
14
|
* Single source of truth for default routing config resolution across all localization functions.
|
|
12
15
|
*/
|
|
13
|
-
const resolveRoutingConfig = (options = {}) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
...options
|
|
21
|
-
};
|
|
22
|
-
};
|
|
16
|
+
const resolveRoutingConfig = (options = {}) => ({
|
|
17
|
+
defaultLocale: _intlayer_config_built.internationalization?.defaultLocale ?? _intlayer_config_defaultValues.DEFAULT_LOCALE,
|
|
18
|
+
mode: _intlayer_config_built.routing?.mode ?? _intlayer_config_defaultValues.ROUTING_MODE,
|
|
19
|
+
locales: _intlayer_config_built.internationalization?.locales ?? _intlayer_config_defaultValues.LOCALES,
|
|
20
|
+
rewrite: _intlayer_config_built.routing?.rewrite,
|
|
21
|
+
...options
|
|
22
|
+
});
|
|
23
23
|
/**
|
|
24
24
|
* Determines the URL prefix for a given locale based on the routing mode configuration.
|
|
25
25
|
*
|
|
@@ -55,7 +55,7 @@ const resolveRoutingConfig = (options = {}) => {
|
|
|
55
55
|
*/
|
|
56
56
|
const getPrefix = (locale, options = {}) => {
|
|
57
57
|
const { defaultLocale, mode, locales } = resolveRoutingConfig(options);
|
|
58
|
-
if (
|
|
58
|
+
if (TREE_SHAKE_PREFIX_MODES || !locale || !locales.includes(locale)) return {
|
|
59
59
|
prefix: "",
|
|
60
60
|
localePrefix: void 0
|
|
61
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrefix.cjs","names":["
|
|
1
|
+
{"version":3,"file":"getPrefix.cjs","names":["internationalization","DEFAULT_LOCALE","routing","ROUTING_MODE","LOCALES"],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n ROUTING_MODE,\n} from '@intlayer/config/defaultValues';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is not a prefix-based\n * mode (neither 'prefix-all' nor 'prefix-no-default').\n */\nconst TREE_SHAKE_PREFIX_MODES =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-all' &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-no-default';\n\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Shared routing options used across all URL localization functions.\n */\nexport type RoutingOptions = {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n};\n\n/**\n * Resolves routing configuration by merging provided options with configuration defaults.\n * Single source of truth for default routing config resolution across all localization functions.\n */\nexport const resolveRoutingConfig = (options: RoutingOptions = {}) => ({\n defaultLocale: internationalization?.defaultLocale ?? DEFAULT_LOCALE,\n mode: routing?.mode ?? ROUTING_MODE,\n locales: internationalization?.locales ?? LOCALES,\n rewrite: routing?.rewrite,\n ...options,\n});\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: RoutingOptions = {}\n): GetPrefixResult => {\n const { defaultLocale, mode, locales } = resolveRoutingConfig(options);\n\n if (TREE_SHAKE_PREFIX_MODES || !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":";;;;;;;;;;AAeA,MAAM,0BACJ,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBACzC,QAAQ,IAAI,6BAA6B;;;;;AAoB3C,MAAa,wBAAwB,UAA0B,EAAE,MAAM;CACrE,eAAeA,6CAAsB,iBAAiBC;CACtD,MAAMC,gCAAS,QAAQC;CACvB,SAASH,6CAAsB,WAAWI;CAC1C,SAASF,gCAAS;CAClB,GAAG;CACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DD,MAAa,aACX,QACA,UAA0B,EAAE,KACR;CACpB,MAAM,EAAE,eAAe,MAAM,YAAY,qBAAqB,QAAQ;AAEtE,KAAI,2BAA2B,CAAC,UAAU,CAAC,QAAQ,SAAS,OAAO,CACjE,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"}
|
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_localization_getPrefix = require('./getPrefix.cjs');
|
|
4
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
6
5
|
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
7
6
|
|
|
8
7
|
//#region src/localization/localeMapper.ts
|
|
@@ -32,7 +31,7 @@ let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
|
32
31
|
* @param mapper - The mapper function that returns an object
|
|
33
32
|
* @returns An array of objects
|
|
34
33
|
*/
|
|
35
|
-
const localeMap = (mapper, locales = _intlayer_config_built.
|
|
34
|
+
const localeMap = (mapper, locales = _intlayer_config_built.internationalization.locales ?? [], defaultLocale = _intlayer_config_built.internationalization.defaultLocale ?? _intlayer_config_defaultValues.DEFAULT_LOCALE, mode = _intlayer_config_built.routing?.mode ?? "prefix-no-default") => (locales ?? []).map((locale) => mapper({
|
|
36
35
|
locale,
|
|
37
36
|
defaultLocale,
|
|
38
37
|
locales,
|
|
@@ -69,7 +68,7 @@ const localeMap = (mapper, locales = _intlayer_config_built.default?.internation
|
|
|
69
68
|
* @param mapper - The mapper function that returns an array of objects
|
|
70
69
|
* @returns An array of objects
|
|
71
70
|
*/
|
|
72
|
-
const localeFlatMap = (mapper, locales = _intlayer_config_built.
|
|
71
|
+
const localeFlatMap = (mapper, locales = _intlayer_config_built.internationalization.locales ?? [], defaultLocale = _intlayer_config_built.internationalization.defaultLocale ?? _intlayer_config_defaultValues.DEFAULT_LOCALE, mode = _intlayer_config_built.routing?.mode ?? "prefix-no-default") => locales.flatMap((locale) => mapper({
|
|
73
72
|
locale,
|
|
74
73
|
defaultLocale,
|
|
75
74
|
locales,
|
|
@@ -103,7 +102,7 @@ const localeFlatMap = (mapper, locales = _intlayer_config_built.default?.interna
|
|
|
103
102
|
* @param mode - URL routing mode for locale handling (defaults to configured value)
|
|
104
103
|
* @returns Record mapping locale codes to mapped values
|
|
105
104
|
*/
|
|
106
|
-
const localeRecord = (mapper, locales = _intlayer_config_built.
|
|
105
|
+
const localeRecord = (mapper, locales = _intlayer_config_built.internationalization.locales ?? [], defaultLocale = _intlayer_config_built.internationalization.defaultLocale ?? _intlayer_config_defaultValues.DEFAULT_LOCALE, mode = _intlayer_config_built.routing?.mode ?? "prefix-no-default") => (locales ?? []).reduce((acc, locale) => {
|
|
107
106
|
acc[locale] = mapper({
|
|
108
107
|
locale,
|
|
109
108
|
defaultLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeMapper.cjs","names":["
|
|
1
|
+
{"version":3,"file":"localeMapper.cjs","names":["internationalization","DEFAULT_LOCALE","routing","getPrefix"],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import { internationalization, routing } 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';\nimport { getPrefix } from './getPrefix';\n\nexport type LocaleData = {\n locale: Locale;\n defaultLocale: Locale;\n isDefault: boolean;\n locales: Locale[];\n urlPrefix: string;\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[] = internationalization.locales ?? [],\n defaultLocale: LocalesValues = internationalization.defaultLocale ??\n DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = 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: getPrefix(locale, { defaultLocale, mode, locales })\n .localePrefix\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[] = internationalization.locales ?? [],\n defaultLocale: LocalesValues = internationalization.defaultLocale ??\n DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = 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: getPrefix(locale, { defaultLocale, mode, locales })\n .localePrefix\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[] = internationalization.locales ?? [],\n defaultLocale: LocalesValues = internationalization.defaultLocale ??\n DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = 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: getPrefix(locale, { defaultLocale, mode, locales })\n .localePrefix\n ? `/${locale}`\n : '',\n } as LocaleData);\n return acc;\n },\n {} as Record<LocalesValues, T>\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,aACX,QACA,UAA2BA,4CAAqB,WAAW,EAAE,EAC7D,gBAA+BA,4CAAqB,iBAClDC,+CACF,OAIsBC,gCAAS,QAAQ,yBAEtC,WAAW,EAAE,EAAE,KAAK,WACnB,OAAO;CACL;CACA;CACA;CACA,WAAW,WAAW;CACtB,WAAWC,yCAAU,QAAQ;EAAE;EAAe;EAAM;EAAS,CAAC,CAC3D,eACC,IAAI,WACJ;CACL,CAAe,CACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BH,MAAa,iBACX,QACA,UAA2BH,4CAAqB,WAAW,EAAE,EAC7D,gBAA+BA,4CAAqB,iBAClDC,+CACF,OAIsBC,gCAAS,QAAQ,wBAEvC,QAAQ,SAAS,WACf,OAAO;CACL;CACA;CACA;CACA,WAAW,WAAW;CACtB,WAAWC,yCAAU,QAAQ;EAAE;EAAe;EAAM;EAAS,CAAC,CAC3D,eACC,IAAI,WACJ;CACL,CAAe,CACjB;;;;;;;;;;;;;;;;;;;;;;;;AAyBH,MAAa,gBACX,QACA,UAA2BH,4CAAqB,WAAW,EAAE,EAC7D,gBAA+BA,4CAAqB,iBAClDC,+CACF,OAIsBC,gCAAS,QAAQ,yBAEtC,WAAW,EAAE,EAAE,QACb,KAAK,WAAW;AACf,KAAI,UAAU,OAAO;EACnB;EACA;EACA;EACA,WAAW,WAAW;EACtB,WAAWC,yCAAU,QAAQ;GAAE;GAAe;GAAM;GAAS,CAAC,CAC3D,eACC,IAAI,WACJ;EACL,CAAe;AAChB,QAAO;GAET,EAAE,CACH"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
5
4
|
|
|
6
5
|
//#region src/localization/localeResolver.ts
|
|
7
6
|
/**
|
|
8
7
|
* Resolves the most specific locale from a user-provided list,
|
|
9
8
|
* or falls back to the default locale if no match is found.
|
|
10
9
|
*/
|
|
11
|
-
const localeResolver = (selectedLocale, locales = _intlayer_config_built.
|
|
10
|
+
const localeResolver = (selectedLocale, locales = _intlayer_config_built.internationalization?.locales, defaultLocale = _intlayer_config_built.internationalization?.defaultLocale) => {
|
|
12
11
|
const requestedLocales = [selectedLocale].flat();
|
|
13
12
|
const normalize = (locale) => locale.trim().toLowerCase();
|
|
14
13
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeResolver.cjs","names":["
|
|
1
|
+
{"version":3,"file":"localeResolver.cjs","names":["internationalization"],"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Resolves the most specific locale from a user-provided list,\n * or falls back to the default locale if no match is found.\n */\nexport const localeResolver = (\n selectedLocale: LocalesValues | LocalesValues[],\n locales: LocalesValues[] = internationalization?.locales,\n defaultLocale: LocalesValues = internationalization?.defaultLocale\n): Locale => {\n // Ensure we can handle both a single locale or an array of locales uniformly\n const requestedLocales = [selectedLocale].flat();\n\n // Simple helper to normalize locale strings (e.g. \"en-US\" => \"en-us\")\n const normalize = (locale: string): string => locale.trim().toLowerCase();\n\n try {\n // Check each requested locale in order\n for (const requested of requestedLocales) {\n const normalizedRequested = normalize(requested);\n\n // Attempt exact match\n const exactMatch = locales.find(\n (locale) => normalize(locale) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch as Locale;\n }\n\n // Attempt partial match on language subtag\n // e.g. if requested is \"en-US\" and not found,\n // see if \"en\" is available among locales\n const [requestedLang] = normalizedRequested.split('-');\n const partialMatch = locales.find(\n (locale) => normalize(locale).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch as Locale;\n }\n }\n } catch {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale as Locale;\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,kBACX,gBACA,UAA2BA,6CAAsB,SACjD,gBAA+BA,6CAAsB,kBAC1C;CAEX,MAAM,mBAAmB,CAAC,eAAe,CAAC,MAAM;CAGhD,MAAM,aAAa,WAA2B,OAAO,MAAM,CAAC,aAAa;AAEzE,KAAI;AAEF,OAAK,MAAM,aAAa,kBAAkB;GACxC,MAAM,sBAAsB,UAAU,UAAU;GAGhD,MAAM,aAAa,QAAQ,MACxB,WAAW,UAAU,OAAO,KAAK,oBACnC;AACD,OAAI,WACF,QAAO;GAMT,MAAM,CAAC,iBAAiB,oBAAoB,MAAM,IAAI;GACtD,MAAM,eAAe,QAAQ,MAC1B,WAAW,UAAU,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,cACjD;AACD,OAAI,aACF,QAAO;;SAGL;AAKR,QAAO"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_config_envVars = require("@intlayer/config/envVars");
|
|
4
2
|
|
|
5
3
|
//#region src/localization/rewriteUtils.ts
|
|
6
4
|
/**
|
|
5
|
+
* True when rewrite rules are explicitly disabled at build time
|
|
6
|
+
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
7
|
+
*/
|
|
8
|
+
const TREE_SHAKE_REWRITE = process.env["INTLAYER_ROUTING_REWRITE_RULES"] === "false";
|
|
9
|
+
/**
|
|
7
10
|
* Normalizes legacy Record format or extracts specialized rules from RewriteObject.
|
|
8
11
|
*/
|
|
9
12
|
const getRewriteRules = (rewrite, context = "url") => {
|
|
10
|
-
if (!rewrite ||
|
|
13
|
+
if (!rewrite || TREE_SHAKE_REWRITE) return void 0;
|
|
11
14
|
if ("url" in rewrite) return rewrite[context];
|
|
12
15
|
return { rules: Object.entries(rewrite).map(([canonical, localized]) => ({
|
|
13
16
|
canonical: canonical.startsWith("/") ? canonical.replace(/\[([^\]]+)\]/g, ":$1") : `/${canonical.replace(/\[([^\]]+)\]/g, ":$1")}`,
|
|
@@ -48,7 +51,7 @@ const extractParams = (url, pattern) => {
|
|
|
48
51
|
* If locale is provided, only check for that locale. Otherwise, check for all locales.
|
|
49
52
|
*/
|
|
50
53
|
const getCanonicalPath = (localizedPath, locale, rewriteRules) => {
|
|
51
|
-
if (!rewriteRules ||
|
|
54
|
+
if (!rewriteRules || TREE_SHAKE_REWRITE) return localizedPath;
|
|
52
55
|
for (const rule of rewriteRules.rules) {
|
|
53
56
|
const { canonical, localized } = rule;
|
|
54
57
|
const localesToCheck = locale ? [locale] : Object.keys(localized);
|
|
@@ -65,7 +68,7 @@ const getCanonicalPath = (localizedPath, locale, rewriteRules) => {
|
|
|
65
68
|
* Given a canonical path (e.g., "/products/123"), finds the localized URL pattern (e.g., "/produits/123").
|
|
66
69
|
*/
|
|
67
70
|
const getLocalizedPath = (canonicalPath, locale, rewriteRules) => {
|
|
68
|
-
if (!rewriteRules ||
|
|
71
|
+
if (!rewriteRules || TREE_SHAKE_REWRITE) return {
|
|
69
72
|
path: canonicalPath,
|
|
70
73
|
isRewritten: false
|
|
71
74
|
};
|
|
@@ -98,7 +101,7 @@ const getInternalPath = (canonicalPath, locale) => {
|
|
|
98
101
|
* Given a current pathname and locale, returns the pretty localized path if a rewrite rule exists and the path is not already localized.
|
|
99
102
|
*/
|
|
100
103
|
const getRewritePath = (pathname, locale, rewrite) => {
|
|
101
|
-
if (
|
|
104
|
+
if (TREE_SHAKE_REWRITE) return void 0;
|
|
102
105
|
const rules = getRewriteRules(rewrite, "url");
|
|
103
106
|
if (!rules) return void 0;
|
|
104
107
|
const { path: localizedPath, isRewritten } = getLocalizedPath(getCanonicalPath(pathname, void 0, rules), locale, rules);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewriteUtils.cjs","names":[
|
|
1
|
+
{"version":3,"file":"rewriteUtils.cjs","names":[],"sources":["../../../src/localization/rewriteUtils.ts"],"sourcesContent":["// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when rewrite rules are explicitly disabled at build time\n * (INTLAYER_ROUTING_REWRITE_RULES === 'false').\n */\nconst TREE_SHAKE_REWRITE =\n process.env['INTLAYER_ROUTING_REWRITE_RULES'] === 'false';\n\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type {\n RewriteObject,\n RewriteRules,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type LocalizedPathResult = {\n path: string;\n isRewritten: boolean;\n};\n\n/**\n * Normalizes legacy Record format or extracts specialized rules from RewriteObject.\n */\nexport const getRewriteRules = (\n rewrite: RoutingConfig['rewrite'],\n context: keyof RewriteObject = 'url'\n): RewriteRules | undefined => {\n if (!rewrite || TREE_SHAKE_REWRITE) return undefined;\n\n if ('url' in rewrite) {\n return (rewrite as RewriteObject)[context];\n }\n\n // Normalize legacy format\n return {\n rules: Object.entries(rewrite).map(([canonical, localized]) => ({\n // Normalize canonical path\n canonical: canonical.startsWith('/')\n ? canonical.replace(/\\[([^\\]]+)\\]/g, ':$1')\n : `/${canonical.replace(/\\[([^\\]]+)\\]/g, ':$1')}`,\n\n // Normalize localized path\n localized: Object.fromEntries(\n Object.entries(localized).map(([locale, pattern]) => {\n const normalizedPattern = pattern?.startsWith('/')\n ? pattern.replace(/\\[([^\\]]+)\\]/g, ':$1')\n : `/${(pattern || '').replace(/\\[([^\\]]+)\\]/g, ':$1')}`;\n return [locale, normalizedPattern];\n })\n ),\n })),\n };\n};\n\n/**\n * Converts normalized pattern to Regex.\n * Internal syntax supports:\n * - :param -> ([^/]+) (one segment)\n * - :param* -> (.*) (zero or more segments)\n * - :param+ -> (.+) (one or more segments)\n * - :param? -> ([^/]*) (zero or one segment)\n */\nconst patternToRegex = (pattern: string) => {\n const regexString = pattern\n .replace(/\\//g, '\\\\/') // Escape slashes\n .replace(/\\\\\\/:(?:[^/\\\\*+?]+)\\*/g, '(?:\\\\/(.*))?') // /:param*\n .replace(/\\\\\\/:(?:[^/\\\\*+?]+)\\?/g, '(?:\\\\/([^\\\\/]+))?') // /:param?\n .replace(/:([^/\\\\*+?]+)\\*/g, '(.*)') // :param* (if no leading slash)\n .replace(/:([^/\\\\*+?]+)\\?/g, '([^\\\\/]*)') // :param? (if no leading slash)\n .replace(/:([^/\\\\*+?]+)\\+/g, '(.+)') // :param+\n .replace(/:([^/\\\\*+?]+)/g, '([^\\\\/]+)'); // :param\n\n return new RegExp(`^${regexString}$`);\n};\n\n/**\n * Replaces route parameters in a path with provided values.\n */\nconst fillPath = (pattern: string, params: string[]) => {\n let index = 0;\n return (\n pattern\n .replace(/:([^/\\\\*+?]+)[*+?]?/g, () => params[index++] ?? '')\n .replace(/\\/+/g, '/')\n .replace(/\\/$/, '') || '/'\n );\n};\n\n/**\n * Extract values from a URL based on a pattern.\n */\nconst extractParams = (url: string, pattern: string): string[] | null => {\n const regex = patternToRegex(pattern);\n const match = url.match(regex);\n return match ? match.slice(1) : null;\n};\n\n/**\n * Given a localized URL (e.g., \"/produits/123\"), finds the canonical internal path (e.g., \"/products/123\").\n * If locale is provided, only check for that locale. Otherwise, check for all locales.\n */\nexport const getCanonicalPath = (\n localizedPath: string,\n locale?: Locale,\n rewriteRules?: RewriteRules\n): string => {\n if (!rewriteRules || TREE_SHAKE_REWRITE) return localizedPath;\n\n for (const rule of rewriteRules.rules) {\n const { canonical, localized } = rule;\n const localesToCheck = locale ? [locale] : Object.keys(localized);\n\n for (const loc of localesToCheck) {\n const localizedPattern = localized[loc as keyof typeof localized];\n\n if (!localizedPattern) continue;\n\n const params = extractParams(localizedPath, localizedPattern);\n\n if (params) {\n return fillPath(canonical, params);\n }\n }\n }\n\n return localizedPath;\n};\n\n/**\n * Given a canonical path (e.g., \"/products/123\"), finds the localized URL pattern (e.g., \"/produits/123\").\n */\nexport const getLocalizedPath = (\n canonicalPath: string,\n locale: LocalesValues,\n rewriteRules?: RewriteRules\n): LocalizedPathResult => {\n if (!rewriteRules || TREE_SHAKE_REWRITE)\n return { path: canonicalPath, isRewritten: false };\n\n for (const rule of rewriteRules.rules) {\n const { canonical, localized } = rule;\n\n // Check if the input path matches a configured canonical pattern\n const params = extractParams(canonicalPath, canonical);\n\n if (params) {\n const targetPattern = localized[locale as keyof typeof localized];\n\n if (targetPattern) {\n return {\n path: fillPath(targetPattern, params),\n isRewritten: true,\n };\n }\n }\n }\n\n return { path: canonicalPath, isRewritten: false };\n};\n\n/**\n * Returns the internal path for a given canonical path and locale.\n * Ensures the locale prefix is present exactly once.\n */\nexport const getInternalPath = (\n canonicalPath: string,\n locale: Locale\n): string => {\n const pathWithLeadingSlash = canonicalPath.startsWith('/')\n ? canonicalPath\n : `/${canonicalPath}`;\n\n if (\n pathWithLeadingSlash.startsWith(`/${locale}/`) ||\n pathWithLeadingSlash === `/${locale}`\n ) {\n return pathWithLeadingSlash;\n }\n\n return `/${locale}${pathWithLeadingSlash === '/' ? '' : pathWithLeadingSlash}`;\n};\n\n/**\n * Given a current pathname and locale, returns the pretty localized path if a rewrite rule exists and the path is not already localized.\n */\nexport const getRewritePath = (\n pathname: string,\n locale: Locale,\n rewrite?: RoutingConfig['rewrite']\n): string | undefined => {\n if (TREE_SHAKE_REWRITE) return undefined;\n const rules = getRewriteRules(rewrite, 'url');\n if (!rules) return undefined;\n\n // Identify canonical path (relative to root, no locale prefix expected in 'url' context)\n const canonicalPath = getCanonicalPath(pathname, undefined, rules);\n\n // Get the localized path for the current locale\n const { path: localizedPath, isRewritten } = getLocalizedPath(\n canonicalPath,\n locale,\n rules\n );\n\n if (isRewritten && localizedPath !== pathname) {\n return localizedPath;\n }\n\n return undefined;\n};\n"],"mappings":";;;;;;;AAQA,MAAM,qBACJ,QAAQ,IAAI,sCAAsC;;;;AAkBpD,MAAa,mBACX,SACA,UAA+B,UACF;AAC7B,KAAI,CAAC,WAAW,mBAAoB,QAAO;AAE3C,KAAI,SAAS,QACX,QAAQ,QAA0B;AAIpC,QAAO,EACL,OAAO,OAAO,QAAQ,QAAQ,CAAC,KAAK,CAAC,WAAW,gBAAgB;EAE9D,WAAW,UAAU,WAAW,IAAI,GAChC,UAAU,QAAQ,iBAAiB,MAAM,GACzC,IAAI,UAAU,QAAQ,iBAAiB,MAAM;EAGjD,WAAW,OAAO,YAChB,OAAO,QAAQ,UAAU,CAAC,KAAK,CAAC,QAAQ,aAAa;AAInD,UAAO,CAAC,QAHkB,SAAS,WAAW,IAAI,GAC9C,QAAQ,QAAQ,iBAAiB,MAAM,GACvC,KAAK,WAAW,IAAI,QAAQ,iBAAiB,MAAM,GACrB;IAClC,CACH;EACF,EAAE,EACJ;;;;;;;;;;AAWH,MAAM,kBAAkB,YAAoB;CAC1C,MAAM,cAAc,QACjB,QAAQ,OAAO,MAAM,CACrB,QAAQ,0BAA0B,eAAe,CACjD,QAAQ,0BAA0B,oBAAoB,CACtD,QAAQ,oBAAoB,OAAO,CACnC,QAAQ,oBAAoB,YAAY,CACxC,QAAQ,oBAAoB,OAAO,CACnC,QAAQ,kBAAkB,YAAY;AAEzC,QAAO,IAAI,OAAO,IAAI,YAAY,GAAG;;;;;AAMvC,MAAM,YAAY,SAAiB,WAAqB;CACtD,IAAI,QAAQ;AACZ,QACE,QACG,QAAQ,8BAA8B,OAAO,YAAY,GAAG,CAC5D,QAAQ,QAAQ,IAAI,CACpB,QAAQ,OAAO,GAAG,IAAI;;;;;AAO7B,MAAM,iBAAiB,KAAa,YAAqC;CACvE,MAAM,QAAQ,eAAe,QAAQ;CACrC,MAAM,QAAQ,IAAI,MAAM,MAAM;AAC9B,QAAO,QAAQ,MAAM,MAAM,EAAE,GAAG;;;;;;AAOlC,MAAa,oBACX,eACA,QACA,iBACW;AACX,KAAI,CAAC,gBAAgB,mBAAoB,QAAO;AAEhD,MAAK,MAAM,QAAQ,aAAa,OAAO;EACrC,MAAM,EAAE,WAAW,cAAc;EACjC,MAAM,iBAAiB,SAAS,CAAC,OAAO,GAAG,OAAO,KAAK,UAAU;AAEjE,OAAK,MAAM,OAAO,gBAAgB;GAChC,MAAM,mBAAmB,UAAU;AAEnC,OAAI,CAAC,iBAAkB;GAEvB,MAAM,SAAS,cAAc,eAAe,iBAAiB;AAE7D,OAAI,OACF,QAAO,SAAS,WAAW,OAAO;;;AAKxC,QAAO;;;;;AAMT,MAAa,oBACX,eACA,QACA,iBACwB;AACxB,KAAI,CAAC,gBAAgB,mBACnB,QAAO;EAAE,MAAM;EAAe,aAAa;EAAO;AAEpD,MAAK,MAAM,QAAQ,aAAa,OAAO;EACrC,MAAM,EAAE,WAAW,cAAc;EAGjC,MAAM,SAAS,cAAc,eAAe,UAAU;AAEtD,MAAI,QAAQ;GACV,MAAM,gBAAgB,UAAU;AAEhC,OAAI,cACF,QAAO;IACL,MAAM,SAAS,eAAe,OAAO;IACrC,aAAa;IACd;;;AAKP,QAAO;EAAE,MAAM;EAAe,aAAa;EAAO;;;;;;AAOpD,MAAa,mBACX,eACA,WACW;CACX,MAAM,uBAAuB,cAAc,WAAW,IAAI,GACtD,gBACA,IAAI;AAER,KACE,qBAAqB,WAAW,IAAI,OAAO,GAAG,IAC9C,yBAAyB,IAAI,SAE7B,QAAO;AAGT,QAAO,IAAI,SAAS,yBAAyB,MAAM,KAAK;;;;;AAM1D,MAAa,kBACX,UACA,QACA,YACuB;AACvB,KAAI,mBAAoB,QAAO;CAC/B,MAAM,QAAQ,gBAAgB,SAAS,MAAM;AAC7C,KAAI,CAAC,MAAO,QAAO;CAMnB,MAAM,EAAE,MAAM,eAAe,gBAAgB,iBAHvB,iBAAiB,UAAU,QAAW,MAAM,EAKhE,QACA,MACD;AAED,KAAI,eAAe,kBAAkB,SACnC,QAAO"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_localization_getPrefix = require('./getPrefix.cjs');
|
|
4
|
-
let _intlayer_config_envVars = require("@intlayer/config/envVars");
|
|
5
3
|
|
|
6
4
|
//#region src/localization/validatePrefix.ts
|
|
7
5
|
/**
|
|
6
|
+
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
7
|
+
*/
|
|
8
|
+
const TREE_SHAKE_NO_PREFIX = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix";
|
|
9
|
+
/**
|
|
10
|
+
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
11
|
+
*/
|
|
12
|
+
const TREE_SHAKE_SEARCH_PARAMS = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params";
|
|
13
|
+
/**
|
|
8
14
|
* Checks whether a given locale is valid based on the configured locales.
|
|
9
15
|
*
|
|
10
16
|
* @param locale - The locale value to validate. Can be `undefined` or `null`.
|
|
@@ -28,7 +34,7 @@ let _intlayer_config_envVars = require("@intlayer/config/envVars");
|
|
|
28
34
|
*/
|
|
29
35
|
const validatePrefix = (locale, options) => {
|
|
30
36
|
const { defaultLocale, mode, locales } = require_localization_getPrefix.resolveRoutingConfig(options);
|
|
31
|
-
if (!
|
|
37
|
+
if (!TREE_SHAKE_NO_PREFIX && mode === "no-prefix" || !TREE_SHAKE_SEARCH_PARAMS && mode === "search-params") return {
|
|
32
38
|
isValid: true,
|
|
33
39
|
localePrefix: void 0
|
|
34
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatePrefix.cjs","names":["resolveRoutingConfig","
|
|
1
|
+
{"version":3,"file":"validatePrefix.cjs","names":["resolveRoutingConfig","getPrefix"],"sources":["../../../src/localization/validatePrefix.ts"],"sourcesContent":["// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is NOT 'no-prefix'.\n */\nconst TREE_SHAKE_NO_PREFIX =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'no-prefix';\n\n/**\n * True when the build-time routing mode is known and is NOT 'search-params'.\n */\nconst TREE_SHAKE_SEARCH_PARAMS =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'search-params';\n\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n getPrefix,\n type RoutingOptions,\n resolveRoutingConfig,\n} 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?: RoutingOptions\n): ValidatePrefixResult => {\n const { defaultLocale, mode, locales } = resolveRoutingConfig(options);\n\n if (\n (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') ||\n (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params')\n ) {\n return { isValid: true, localePrefix: undefined };\n }\n\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 const isValid = locales.some((localeEl) => localeEl === locale);\n\n return { isValid, localePrefix };\n};\n"],"mappings":";;;;;;;AAOA,MAAM,uBACJ,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;AAK3C,MAAM,2BACJ,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;AAoC3C,MAAa,kBACX,QACA,YACyB;CACzB,MAAM,EAAE,eAAe,MAAM,YAAYA,oDAAqB,QAAQ;AAEtE,KACG,CAAC,wBAAwB,SAAS,eAClC,CAAC,4BAA4B,SAAS,gBAEvC,QAAO;EAAE,SAAS;EAAM,cAAc;EAAW;CAGnD,MAAM,EAAE,iBAAiBC,yCAAU,UAAU,eAAe;EAC1D;EACA;EACA;EACD,CAAC;AAEF,KAAI,iBAAiB,UAAU,WAAW,OACxC,QAAO;EAAE,SAAS;EAAM,cAAc;EAAW;AAKnD,QAAO;EAAE,SAFO,QAAQ,MAAM,aAAa,aAAa,OAAO;EAE7C;EAAc"}
|
package/dist/cjs/utils/intl.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
5
4
|
|
|
6
5
|
//#region src/utils/intl.ts
|
|
7
6
|
/**
|
|
@@ -35,7 +34,7 @@ const cache = /* @__PURE__ */ new Map();
|
|
|
35
34
|
* Generic caching instantiator for Intl constructors.
|
|
36
35
|
*/
|
|
37
36
|
const getCachedIntl = (Ctor, locale, options) => {
|
|
38
|
-
const resLoc = locale ?? _intlayer_config_built.
|
|
37
|
+
const resLoc = locale ?? _intlayer_config_built.internationalization?.defaultLocale;
|
|
39
38
|
const key = `${resLoc}|${options ? JSON.stringify(options) : ""}`;
|
|
40
39
|
let ctorCache = cache.get(Ctor);
|
|
41
40
|
if (!ctorCache) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.cjs","names":["
|
|
1
|
+
{"version":3,"file":"intl.cjs","names":["internationalization"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["/**\n * 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 @example:\n * ---------------\n * ```ts\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 { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nconst MAX_CACHE_SIZE = 50;\nconst cache = new Map<any, Map<string, any>>();\n\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\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? {\n new (locales?: LocalesValues, options?: Options): Instance;\n new (options?: Options & { locale?: LocalesValues }): Instance;\n (locales?: LocalesValues, options?: Options): Instance;\n (options?: Options & { locale?: LocalesValues }): Instance;\n }\n : T extends new (\n locales: any\n ) => infer Instance\n ? {\n new (locales?: LocalesValues): Instance;\n new (options?: { locale?: LocalesValues }): Instance;\n (locales?: LocalesValues): Instance;\n (options?: { locale?: LocalesValues }): Instance;\n }\n : T;\n\nexport type WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n/**\n * Generic caching instantiator for Intl constructors.\n */\nexport const getCachedIntl = <T extends new (...args: any[]) => any>(\n Ctor: T,\n locale?: LocalesValues | string,\n options?: any\n): InstanceType<T> => {\n const resLoc = locale ?? internationalization?.defaultLocale;\n\n const optKey = options ? JSON.stringify(options) : '';\n const key = `${resLoc}|${optKey}`;\n\n let ctorCache = cache.get(Ctor);\n\n if (!ctorCache) {\n ctorCache = new Map();\n cache.set(Ctor, ctorCache);\n }\n\n let instance = ctorCache.get(key);\n\n if (!instance) {\n if (ctorCache.size > MAX_CACHE_SIZE) ctorCache.clear();\n instance = new Ctor(resLoc, options);\n ctorCache.set(key, instance);\n }\n return instance;\n};\n\n/**\n * Optional: Keep bindIntl if your library exports it publicly.\n * It now uses the much smaller getCachedIntl under the hood.\n */\nexport const bindIntl = (boundLocale: LocalesValues): WrappedIntl => {\n const bindWrap = (Ctor: any) =>\n // function is used as a constructor, do not change in arrow function\n function intlConstructor(locales?: any, options?: any) {\n const isOptsFirst =\n locales !== null &&\n typeof locales === 'object' &&\n !Array.isArray(locales);\n const resOpts = isOptsFirst ? locales : options;\n const resLoc = isOptsFirst\n ? (resOpts as any).locale || boundLocale\n : locales || boundLocale;\n\n return getCachedIntl(Ctor, resLoc, resOpts);\n };\n\n return {\n ...Intl,\n Collator: bindWrap(Intl.Collator),\n DateTimeFormat: bindWrap(Intl.DateTimeFormat),\n DisplayNames: bindWrap(Intl.DisplayNames),\n ListFormat: bindWrap(Intl.ListFormat),\n NumberFormat: bindWrap(Intl.NumberFormat),\n PluralRules: bindWrap(Intl.PluralRules),\n RelativeTimeFormat: bindWrap(Intl.RelativeTimeFormat),\n Locale: bindWrap(Intl.Locale),\n Segmenter: bindWrap((Intl as any).Segmenter),\n } as unknown as WrappedIntl;\n};\n\n// Add this to the bottom of utils/intl.ts ONLY if required for public API compatibility.\nexport const CachedIntl = {\n // function is used as a constructor, do not change in arrow function\n Collator: function Collator(locales?: any, options?: any) {\n return getCachedIntl(Intl.Collator, locales, options);\n },\n DateTimeFormat: function DateTimeFormat(locales?: any, options?: any) {\n return getCachedIntl(Intl.DateTimeFormat, locales, options);\n },\n DisplayNames: function DisplayNames(locales?: any, options?: any) {\n return getCachedIntl(Intl.DisplayNames, locales, options);\n },\n ListFormat: function ListFormat(locales?: any, options?: any) {\n return getCachedIntl(Intl.ListFormat as any, locales, options);\n },\n NumberFormat: function NumberFormat(locales?: any, options?: any) {\n return getCachedIntl(Intl.NumberFormat, locales, options);\n },\n PluralRules: function PluralRules(locales?: any, options?: any) {\n return getCachedIntl(Intl.PluralRules, locales, options);\n },\n RelativeTimeFormat: function RelativeTimeFormat(\n locales?: any,\n options?: any\n ) {\n return getCachedIntl(Intl.RelativeTimeFormat, locales, options);\n },\n Segmenter: function Segmenter(locales?: any, options?: any) {\n return getCachedIntl((Intl as any).Segmenter, locales, options);\n },\n} as any; // Cast to 'any' internally to avoid TS readonly errors\n\nexport { CachedIntl as Intl };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,iBAAiB;AACvB,MAAM,wBAAQ,IAAI,KAA4B;;;;AAwC9C,MAAa,iBACX,MACA,QACA,YACoB;CACpB,MAAM,SAAS,UAAUA,6CAAsB;CAG/C,MAAM,MAAM,GAAG,OAAO,GADP,UAAU,KAAK,UAAU,QAAQ,GAAG;CAGnD,IAAI,YAAY,MAAM,IAAI,KAAK;AAE/B,KAAI,CAAC,WAAW;AACd,8BAAY,IAAI,KAAK;AACrB,QAAM,IAAI,MAAM,UAAU;;CAG5B,IAAI,WAAW,UAAU,IAAI,IAAI;AAEjC,KAAI,CAAC,UAAU;AACb,MAAI,UAAU,OAAO,eAAgB,WAAU,OAAO;AACtD,aAAW,IAAI,KAAK,QAAQ,QAAQ;AACpC,YAAU,IAAI,KAAK,SAAS;;AAE9B,QAAO;;;;;;AAOT,MAAa,YAAY,gBAA4C;CACnE,MAAM,YAAY,SAEhB,SAAS,gBAAgB,SAAe,SAAe;EACrD,MAAM,cACJ,YAAY,QACZ,OAAO,YAAY,YACnB,CAAC,MAAM,QAAQ,QAAQ;EACzB,MAAM,UAAU,cAAc,UAAU;AAKxC,SAAO,cAAc,MAJN,cACV,QAAgB,UAAU,cAC3B,WAAW,aAEoB,QAAQ;;AAG/C,QAAO;EACL,GAAG;EACH,UAAU,SAAS,KAAK,SAAS;EACjC,gBAAgB,SAAS,KAAK,eAAe;EAC7C,cAAc,SAAS,KAAK,aAAa;EACzC,YAAY,SAAS,KAAK,WAAW;EACrC,cAAc,SAAS,KAAK,aAAa;EACzC,aAAa,SAAS,KAAK,YAAY;EACvC,oBAAoB,SAAS,KAAK,mBAAmB;EACrD,QAAQ,SAAS,KAAK,OAAO;EAC7B,WAAW,SAAU,KAAa,UAAU;EAC7C;;AAIH,MAAa,aAAa;CAExB,UAAU,SAAS,SAAS,SAAe,SAAe;AACxD,SAAO,cAAc,KAAK,UAAU,SAAS,QAAQ;;CAEvD,gBAAgB,SAAS,eAAe,SAAe,SAAe;AACpE,SAAO,cAAc,KAAK,gBAAgB,SAAS,QAAQ;;CAE7D,cAAc,SAAS,aAAa,SAAe,SAAe;AAChE,SAAO,cAAc,KAAK,cAAc,SAAS,QAAQ;;CAE3D,YAAY,SAAS,WAAW,SAAe,SAAe;AAC5D,SAAO,cAAc,KAAK,YAAmB,SAAS,QAAQ;;CAEhE,cAAc,SAAS,aAAa,SAAe,SAAe;AAChE,SAAO,cAAc,KAAK,cAAc,SAAS,QAAQ;;CAE3D,aAAa,SAAS,YAAY,SAAe,SAAe;AAC9D,SAAO,cAAc,KAAK,aAAa,SAAS,QAAQ;;CAE1D,oBAAoB,SAAS,mBAC3B,SACA,SACA;AACA,SAAO,cAAc,KAAK,oBAAoB,SAAS,QAAQ;;CAEjE,WAAW,SAAS,UAAU,SAAe,SAAe;AAC1D,SAAO,cAAe,KAAa,WAAW,SAAS,QAAQ;;CAElE"}
|
|
@@ -2,10 +2,24 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_utils_getCookie = require('./getCookie.cjs');
|
|
4
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
6
|
-
let _intlayer_config_envVars = require("@intlayer/config/envVars");
|
|
7
5
|
|
|
8
6
|
//#region src/utils/localeStorage.ts
|
|
7
|
+
/**
|
|
8
|
+
* True when cookie storage is explicitly disabled at build time.
|
|
9
|
+
*/
|
|
10
|
+
const TREE_SHAKE_STORAGE_COOKIES = process.env["INTLAYER_ROUTING_STORAGE_COOKIES"] === "false";
|
|
11
|
+
/**
|
|
12
|
+
* True when localStorage is explicitly disabled at build time.
|
|
13
|
+
*/
|
|
14
|
+
const TREE_SHAKE_STORAGE_LOCAL_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_LOCALSTORAGE"] === "false";
|
|
15
|
+
/**
|
|
16
|
+
* True when sessionStorage is explicitly disabled at build time.
|
|
17
|
+
*/
|
|
18
|
+
const TREE_SHAKE_STORAGE_SESSION_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE"] === "false";
|
|
19
|
+
/**
|
|
20
|
+
* True when header storage is explicitly disabled at build time.
|
|
21
|
+
*/
|
|
22
|
+
const TREE_SHAKE_STORAGE_HEADERS = process.env["INTLAYER_ROUTING_STORAGE_HEADERS"] === "false";
|
|
9
23
|
const buildCookieString = (name, value, attributes) => {
|
|
10
24
|
const parts = [`${name}=${encodeURIComponent(value)}`];
|
|
11
25
|
if (attributes.path) parts.push(`Path=${attributes.path}`);
|
|
@@ -21,20 +35,19 @@ const buildCookieString = (name, value, attributes) => {
|
|
|
21
35
|
* Does not read from headers — use `getLocaleFromStorageServer` for that.
|
|
22
36
|
*/
|
|
23
37
|
const getLocaleFromStorageClient = (options) => {
|
|
24
|
-
const {
|
|
25
|
-
const
|
|
26
|
-
const storageAttributes = routing.storage;
|
|
38
|
+
const { locales } = _intlayer_config_built.internationalization;
|
|
39
|
+
const storageAttributes = _intlayer_config_built.routing.storage;
|
|
27
40
|
if (options?.isCookieEnabled === false) return void 0;
|
|
28
41
|
const isValidLocale = (value) => !!value && locales.includes(value);
|
|
29
|
-
if (!
|
|
42
|
+
if (!TREE_SHAKE_STORAGE_COOKIES) for (let i = 0; i < (storageAttributes.cookies ?? []).length; i++) try {
|
|
30
43
|
const value = options?.getCookie?.(storageAttributes.cookies[i].name);
|
|
31
44
|
if (isValidLocale(value)) return value;
|
|
32
45
|
} catch {}
|
|
33
|
-
if (!
|
|
46
|
+
if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) for (let i = 0; i < (storageAttributes.localStorage ?? []).length; i++) try {
|
|
34
47
|
const value = options?.getLocaleStorage?.(storageAttributes.localStorage[i].name);
|
|
35
48
|
if (isValidLocale(value)) return value;
|
|
36
49
|
} catch {}
|
|
37
|
-
if (!
|
|
50
|
+
if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && storageAttributes.sessionStorage) for (let i = 0; i < storageAttributes.sessionStorage.length; i++) try {
|
|
38
51
|
const value = options?.getSessionStorage?.(storageAttributes.sessionStorage[i].name);
|
|
39
52
|
if (isValidLocale(value)) return value;
|
|
40
53
|
} catch {}
|
|
@@ -45,10 +58,9 @@ const getLocaleFromStorageClient = (options) => {
|
|
|
45
58
|
* Does not write to headers — use `setLocaleInStorageServer` for that.
|
|
46
59
|
*/
|
|
47
60
|
const setLocaleInStorageClient = (locale, options) => {
|
|
48
|
-
const
|
|
49
|
-
const storageAttributes = routing.storage;
|
|
61
|
+
const storageAttributes = _intlayer_config_built.routing.storage;
|
|
50
62
|
if (options?.isCookieEnabled === false) return;
|
|
51
|
-
if (!
|
|
63
|
+
if (!TREE_SHAKE_STORAGE_COOKIES && storageAttributes.cookies) for (let i = 0; i < storageAttributes.cookies.length; i++) {
|
|
52
64
|
const { name, attributes } = storageAttributes.cookies[i];
|
|
53
65
|
try {
|
|
54
66
|
if (options?.setCookieStore) options.setCookieStore(name, locale, {
|
|
@@ -61,7 +73,7 @@ const setLocaleInStorageClient = (locale, options) => {
|
|
|
61
73
|
} catch {}
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
|
-
if (!
|
|
76
|
+
if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE && storageAttributes.localStorage && options?.setLocaleStorage) for (let i = 0; i < storageAttributes.localStorage.length; i++) {
|
|
65
77
|
const { name } = storageAttributes.localStorage[i];
|
|
66
78
|
try {
|
|
67
79
|
if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {
|
|
@@ -70,7 +82,7 @@ const setLocaleInStorageClient = (locale, options) => {
|
|
|
70
82
|
options.setLocaleStorage(name, locale);
|
|
71
83
|
} catch {}
|
|
72
84
|
}
|
|
73
|
-
if (!
|
|
85
|
+
if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && storageAttributes.sessionStorage && options?.setSessionStorage) for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {
|
|
74
86
|
const { name } = storageAttributes.sessionStorage[i];
|
|
75
87
|
try {
|
|
76
88
|
if (!(options?.overwrite ?? true) && options?.getSessionStorage) {
|
|
@@ -102,16 +114,15 @@ const LocaleStorageClient = (options) => ({
|
|
|
102
114
|
* No browser cookie fallback — the caller must provide `getCookie`.
|
|
103
115
|
*/
|
|
104
116
|
const getLocaleFromStorageServer = (options) => {
|
|
105
|
-
const {
|
|
106
|
-
const
|
|
107
|
-
const storageAttributes = routing.storage;
|
|
117
|
+
const { locales } = _intlayer_config_built.internationalization;
|
|
118
|
+
const storageAttributes = _intlayer_config_built.routing.storage;
|
|
108
119
|
if (options?.isCookieEnabled === false) return void 0;
|
|
109
120
|
const isValidLocale = (value) => !!value && locales.includes(value);
|
|
110
|
-
if (!
|
|
121
|
+
if (!TREE_SHAKE_STORAGE_COOKIES && storageAttributes.cookies) for (let i = 0; i < storageAttributes.cookies.length; i++) try {
|
|
111
122
|
const value = options?.getCookie?.(storageAttributes.cookies[i].name);
|
|
112
123
|
if (isValidLocale(value)) return value;
|
|
113
124
|
} catch {}
|
|
114
|
-
if (!
|
|
125
|
+
if (!TREE_SHAKE_STORAGE_HEADERS && storageAttributes.headers) for (let i = 0; i < storageAttributes.headers.length; i++) try {
|
|
115
126
|
const value = options?.getHeader?.(storageAttributes.headers[i].name);
|
|
116
127
|
if (isValidLocale(value)) return value;
|
|
117
128
|
} catch {}
|
|
@@ -121,10 +132,9 @@ const getLocaleFromStorageServer = (options) => {
|
|
|
121
132
|
* Does not write to localStorage or sessionStorage.
|
|
122
133
|
*/
|
|
123
134
|
const setLocaleInStorageServer = (locale, options) => {
|
|
124
|
-
const
|
|
125
|
-
const storageAttributes = routing.storage;
|
|
135
|
+
const storageAttributes = _intlayer_config_built.routing.storage;
|
|
126
136
|
if (options?.isCookieEnabled === false) return;
|
|
127
|
-
if (!
|
|
137
|
+
if (!TREE_SHAKE_STORAGE_COOKIES && storageAttributes.cookies) for (let i = 0; i < storageAttributes.cookies.length; i++) {
|
|
128
138
|
const { name, attributes } = storageAttributes.cookies[i];
|
|
129
139
|
try {
|
|
130
140
|
if (options?.setCookieStore) options.setCookieStore(name, locale, {
|
|
@@ -137,7 +147,7 @@ const setLocaleInStorageServer = (locale, options) => {
|
|
|
137
147
|
} catch {}
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
|
-
if (!
|
|
150
|
+
if (!TREE_SHAKE_STORAGE_HEADERS && storageAttributes.headers && options?.setHeader) for (let i = 0; i < storageAttributes.headers.length; i++) try {
|
|
141
151
|
options.setHeader(storageAttributes.headers[i].name, locale);
|
|
142
152
|
} catch {}
|
|
143
153
|
};
|
|
@@ -170,9 +180,8 @@ const LocaleStorageServer = (options) => ({
|
|
|
170
180
|
* {@link getLocaleFromStorageServer} (server) instead.
|
|
171
181
|
*/
|
|
172
182
|
const getLocaleFromStorage = (options) => {
|
|
173
|
-
const {
|
|
174
|
-
const
|
|
175
|
-
const storageAttributes = routing.storage;
|
|
183
|
+
const { locales } = _intlayer_config_built.internationalization;
|
|
184
|
+
const storageAttributes = _intlayer_config_built.routing.storage;
|
|
176
185
|
if (options?.isCookieEnabled === false) return void 0;
|
|
177
186
|
const isValidLocale = (value) => !!value && locales.includes(value);
|
|
178
187
|
const readCookie = (name) => {
|
|
@@ -182,19 +191,19 @@ const getLocaleFromStorage = (options) => {
|
|
|
182
191
|
} catch {}
|
|
183
192
|
return require_utils_getCookie.getCookie(name);
|
|
184
193
|
};
|
|
185
|
-
if (!
|
|
194
|
+
if (!TREE_SHAKE_STORAGE_COOKIES && storageAttributes.cookies) for (let i = 0; i < storageAttributes.cookies.length; i++) {
|
|
186
195
|
const value = readCookie(storageAttributes.cookies[i].name);
|
|
187
196
|
if (isValidLocale(value)) return value;
|
|
188
197
|
}
|
|
189
|
-
if (!
|
|
198
|
+
if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE && storageAttributes.localStorage) for (let i = 0; i < storageAttributes.localStorage.length; i++) try {
|
|
190
199
|
const value = options?.getLocaleStorage?.(storageAttributes.localStorage[i].name);
|
|
191
200
|
if (isValidLocale(value)) return value;
|
|
192
201
|
} catch {}
|
|
193
|
-
if (!
|
|
202
|
+
if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && storageAttributes.sessionStorage) for (let i = 0; i < storageAttributes.sessionStorage.length; i++) try {
|
|
194
203
|
const value = options?.getSessionStorage?.(storageAttributes.sessionStorage[i].name);
|
|
195
204
|
if (isValidLocale(value)) return value;
|
|
196
205
|
} catch {}
|
|
197
|
-
if (!
|
|
206
|
+
if (!TREE_SHAKE_STORAGE_HEADERS && storageAttributes.headers) for (let i = 0; i < storageAttributes.headers.length; i++) try {
|
|
198
207
|
const value = options?.getHeader?.(storageAttributes.headers[i].name);
|
|
199
208
|
if (isValidLocale(value)) return value;
|
|
200
209
|
} catch {}
|
|
@@ -207,10 +216,9 @@ const getLocaleFromStorage = (options) => {
|
|
|
207
216
|
* {@link setLocaleInStorageServer} (server) instead.
|
|
208
217
|
*/
|
|
209
218
|
const setLocaleInStorage = (locale, options) => {
|
|
210
|
-
const
|
|
211
|
-
const storageAttributes = routing.storage;
|
|
219
|
+
const storageAttributes = _intlayer_config_built.routing.storage;
|
|
212
220
|
if (options?.isCookieEnabled === false) return;
|
|
213
|
-
if (!
|
|
221
|
+
if (!TREE_SHAKE_STORAGE_COOKIES && storageAttributes.cookies) for (let i = 0; i < storageAttributes.cookies.length; i++) {
|
|
214
222
|
const { name, attributes } = storageAttributes.cookies[i];
|
|
215
223
|
try {
|
|
216
224
|
if (options?.setCookieStore) options.setCookieStore(name, locale, {
|
|
@@ -223,7 +231,7 @@ const setLocaleInStorage = (locale, options) => {
|
|
|
223
231
|
} catch {}
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
|
-
if (!
|
|
234
|
+
if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE && storageAttributes.localStorage && options?.setLocaleStorage) for (let i = 0; i < storageAttributes.localStorage.length; i++) {
|
|
227
235
|
const { name } = storageAttributes.localStorage[i];
|
|
228
236
|
try {
|
|
229
237
|
if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {
|
|
@@ -232,7 +240,7 @@ const setLocaleInStorage = (locale, options) => {
|
|
|
232
240
|
options.setLocaleStorage(name, locale);
|
|
233
241
|
} catch {}
|
|
234
242
|
}
|
|
235
|
-
if (!
|
|
243
|
+
if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && storageAttributes.sessionStorage && options?.setSessionStorage) for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {
|
|
236
244
|
const { name } = storageAttributes.sessionStorage[i];
|
|
237
245
|
try {
|
|
238
246
|
if (!(options?.overwrite ?? true) && options?.getSessionStorage) {
|
|
@@ -241,7 +249,7 @@ const setLocaleInStorage = (locale, options) => {
|
|
|
241
249
|
options.setSessionStorage(name, locale);
|
|
242
250
|
} catch {}
|
|
243
251
|
}
|
|
244
|
-
if (!
|
|
252
|
+
if (!TREE_SHAKE_STORAGE_HEADERS && storageAttributes.headers && options?.setHeader) for (let i = 0; i < storageAttributes.headers.length; i++) try {
|
|
245
253
|
options.setHeader(storageAttributes.headers[i].name, locale);
|
|
246
254
|
} catch {}
|
|
247
255
|
};
|