@intlayer/core 5.3.13 → 5.4.0

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.
Files changed (31) hide show
  1. package/dist/cjs/index.cjs +9 -9
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/localization/getLocaleFromPath.cjs +59 -0
  4. package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -0
  5. package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
  6. package/dist/cjs/localization/index.cjs +13 -5
  7. package/dist/cjs/localization/index.cjs.map +1 -1
  8. package/dist/cjs/localization/localeMapper.cjs +59 -0
  9. package/dist/cjs/localization/localeMapper.cjs.map +1 -0
  10. package/dist/cjs/localization/localeResolver.cjs.map +1 -1
  11. package/dist/esm/index.mjs +4 -4
  12. package/dist/esm/index.mjs.map +1 -1
  13. package/dist/esm/localization/getLocaleFromPath.mjs +25 -0
  14. package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -0
  15. package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
  16. package/dist/esm/localization/index.mjs +10 -5
  17. package/dist/esm/localization/index.mjs.map +1 -1
  18. package/dist/esm/localization/localeMapper.mjs +24 -0
  19. package/dist/esm/localization/localeMapper.mjs.map +1 -0
  20. package/dist/esm/localization/localeResolver.mjs.map +1 -1
  21. package/dist/types/index.d.ts +4 -4
  22. package/dist/types/index.d.ts.map +1 -1
  23. package/dist/types/localization/getLocaleFromPath.d.ts +22 -0
  24. package/dist/types/localization/getLocaleFromPath.d.ts.map +1 -0
  25. package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
  26. package/dist/types/localization/index.d.ts +7 -5
  27. package/dist/types/localization/index.d.ts.map +1 -1
  28. package/dist/types/localization/localeMapper.d.ts +63 -0
  29. package/dist/types/localization/localeMapper.d.ts.map +1 -0
  30. package/dist/types/localization/localeResolver.d.ts.map +1 -1
  31. package/package.json +9 -9
@@ -15,23 +15,23 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var index_exports = {};
17
17
  module.exports = __toCommonJS(index_exports);
18
- __reExport(index_exports, require('./transpiler/index.cjs'), module.exports);
19
- __reExport(index_exports, require('./interpreter/index.cjs'), module.exports);
20
18
  __reExport(index_exports, require('./dictionaryManipulator/index.cjs'), module.exports);
19
+ __reExport(index_exports, require('./interpreter/index.cjs'), module.exports);
20
+ __reExport(index_exports, require('./localization/index.cjs'), module.exports);
21
+ __reExport(index_exports, require('./transpiler/index.cjs'), module.exports);
21
22
  __reExport(index_exports, require('./types/index.cjs'), module.exports);
22
- __reExport(index_exports, require('./utils/isSameKeyPath.cjs'), module.exports);
23
23
  __reExport(index_exports, require('./utils/checkIsURLAbsolute.cjs'), module.exports);
24
+ __reExport(index_exports, require('./utils/isSameKeyPath.cjs'), module.exports);
24
25
  __reExport(index_exports, require('./utils/isValidReactElement.cjs'), module.exports);
25
- __reExport(index_exports, require('./localization/index.cjs'), module.exports);
26
26
  // Annotate the CommonJS export names for ESM import in node:
27
27
  0 && (module.exports = {
28
- ...require('./transpiler/index.cjs'),
29
- ...require('./interpreter/index.cjs'),
30
28
  ...require('./dictionaryManipulator/index.cjs'),
29
+ ...require('./interpreter/index.cjs'),
30
+ ...require('./localization/index.cjs'),
31
+ ...require('./transpiler/index.cjs'),
31
32
  ...require('./types/index.cjs'),
32
- ...require('./utils/isSameKeyPath.cjs'),
33
33
  ...require('./utils/checkIsURLAbsolute.cjs'),
34
- ...require('./utils/isValidReactElement.cjs'),
35
- ...require('./localization/index.cjs')
34
+ ...require('./utils/isSameKeyPath.cjs'),
35
+ ...require('./utils/isValidReactElement.cjs')
36
36
  });
37
37
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './transpiler/index';\nexport * from './interpreter/index';\nexport * from './dictionaryManipulator/index';\nexport * from './types/index';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isValidReactElement';\nexport * from './localization/index';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,+BAAd;AACA,0BAAc,gCADd;AAEA,0BAAc,0CAFd;AAGA,0BAAc,0BAHd;AAIA,0BAAc,kCAJd;AAKA,0BAAc,uCALd;AAMA,0BAAc,wCANd;AAOA,0BAAc,iCAPd;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;AACA,0BAAc,gCADd;AAEA,0BAAc,iCAFd;AAGA,0BAAc,+BAHd;AAIA,0BAAc,0BAJd;AAKA,0BAAc,uCALd;AAMA,0BAAc,kCANd;AAOA,0BAAc,wCAPd;","names":[]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var getLocaleFromPath_exports = {};
30
+ __export(getLocaleFromPath_exports, {
31
+ getLocaleFromPath: () => getLocaleFromPath
32
+ });
33
+ module.exports = __toCommonJS(getLocaleFromPath_exports);
34
+ var import_built = __toESM(require("@intlayer/config/built"));
35
+ var import_checkIsURLAbsolute = require('../utils/checkIsURLAbsolute.cjs');
36
+ const getLocaleFromPath = (inputUrl) => {
37
+ const { defaultLocale, locales } = import_built.default.internationalization;
38
+ const isAbsoluteUrl = (0, import_checkIsURLAbsolute.checkIsURLAbsolute)(inputUrl);
39
+ let fixedInputUrl = inputUrl;
40
+ if (inputUrl.endsWith("/")) {
41
+ fixedInputUrl = inputUrl.slice(0, -1);
42
+ }
43
+ const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
44
+ const pathname = url.pathname;
45
+ if (!pathname.startsWith("/")) {
46
+ return defaultLocale;
47
+ }
48
+ const pathSegments = pathname.split("/");
49
+ const firstSegment = pathSegments[1];
50
+ if (firstSegment && locales.includes(firstSegment)) {
51
+ return firstSegment;
52
+ }
53
+ return defaultLocale;
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ getLocaleFromPath
58
+ });
59
+ //# sourceMappingURL=getLocaleFromPath.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales } from '@intlayer/config/client';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Extracts the locale segment from the given URL or pathname if present.\n * If no locale is present, returns the default locale (en).\n *\n * Example:\n *\n * ```ts\n * getLocaleFromPath('/en/dashboard') // Returns 'en'\n * getLocaleFromPath('/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('/dashboard') // Returns 'en'\n * getLocaleFromPath('dashboard') // Returns 'en'\n * getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'\n * getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('https://example.com/dashboard') // Returns 'en'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @returns The detected locale or default (en) if no locale is found\n */\nexport const getLocaleFromPath = (inputUrl: string): Locales => {\n // Define supported locales array\n const { defaultLocale, locales } = configuration.internationalization;\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\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 url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the default locale\n return defaultLocale;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (firstSegment && locales.includes(firstSegment as Locales)) {\n // Return the detected locale\n return firstSegment as Locales;\n }\n\n // Return the default locale if no locale is found in the path\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,gCAAmC;AAqB5B,MAAM,oBAAoB,CAAC,aAA8B;AAE9D,QAAM,EAAE,eAAe,QAAQ,IAAI,aAAAA,QAAc;AAGjD,QAAM,oBAAgB,8CAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,WAAO;AAAA,EACT;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,gBAAgB,QAAQ,SAAS,YAAuB,GAAG;AAE7D,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":["configuration"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration.internationalization\n .locales as LocalesValues[]\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\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 url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales.includes(firstSegment as Locales)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAE1B,gCAAmC;AAuB5B,MAAM,uBAAuB,CAClC,UACA,UAA2B,aAAAA,QAAc,qBACtC,YACQ;AAEX,QAAM,oBAAgB,8CAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,QAAI,WAAW,IAAI,QAAQ;AAAA,EAC7B;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,QAAQ,SAAS,YAAuB,GAAG;AAE7C,iBAAa,OAAO,GAAG,CAAC;AAGxB,UAAM,cAAc,aAAa,KAAK,GAAG,KAAK;AAC9C,QAAI,WAAW;AAAA,EACjB;AAEA,MAAI,eAAe;AAEjB,WAAO,IAAI,SAAS;AAAA,EACtB;AAGA,SAAO,IAAI,SAAS,EAAE,QAAQ,sBAAsB,EAAE;AACxD;","names":["configuration"]}
1
+ {"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locales, type LocalesValues } from '@intlayer/config/client';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration.internationalization\n .locales as LocalesValues[]\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\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 url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales.includes(firstSegment as Locales)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,gCAAmC;AAuB5B,MAAM,uBAAuB,CAClC,UACA,UAA2B,aAAAA,QAAc,qBACtC,YACQ;AAEX,QAAM,oBAAgB,8CAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,QAAI,WAAW,IAAI,QAAQ;AAAA,EAC7B;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,QAAQ,SAAS,YAAuB,GAAG;AAE7C,iBAAa,OAAO,GAAG,CAAC;AAGxB,UAAM,cAAc,aAAa,KAAK,GAAG,KAAK;AAC9C,QAAI,WAAW;AAAA,EACjB;AAEA,MAAI,eAAe;AAEjB,WAAO,IAAI,SAAS;AAAA,EACtB;AAGA,SAAO,IAAI,SAAS,EAAE,QAAQ,sBAAsB,EAAE;AACxD;","names":["configuration"]}
@@ -19,35 +19,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var localization_exports = {};
20
20
  __export(localization_exports, {
21
21
  getHTMLTextDir: () => import_getHTMLTextDir.getHTMLTextDir,
22
+ getLocaleFromPath: () => import_getLocaleFromPath.getLocaleFromPath,
22
23
  getLocaleLang: () => import_getLocaleLang.getLocaleLang,
23
24
  getLocaleName: () => import_getLocaleName.getLocaleName,
24
25
  getLocalizedUrl: () => import_getLocalizedUrl.getLocalizedUrl,
25
26
  getMultilingualUrls: () => import_getMultilingualUrls.getMultilingualUrls,
26
27
  getPathWithoutLocale: () => import_getPathWithoutLocale.getPathWithoutLocale,
27
28
  localeDetector: () => import_localeDetector.localeDetector,
29
+ localeFlatMap: () => import_localeMapper.localeFlatMap,
28
30
  localeList: () => import_localeList.localeList,
31
+ localeMap: () => import_localeMapper.localeMap,
29
32
  localeResolver: () => import_localeResolver.localeResolver
30
33
  });
31
34
  module.exports = __toCommonJS(localization_exports);
32
- var import_getLocaleName = require('./getLocaleName.cjs');
33
35
  var import_getHTMLTextDir = require('./getHTMLTextDir.cjs');
36
+ var import_getLocaleFromPath = require('./getLocaleFromPath.cjs');
34
37
  var import_getLocaleLang = require('./getLocaleLang.cjs');
38
+ var import_getLocaleName = require('./getLocaleName.cjs');
39
+ var import_getLocalizedUrl = require('./getLocalizedUrl.cjs');
40
+ var import_getMultilingualUrls = require('./getMultilingualUrls.cjs');
41
+ var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
42
+ var import_localeDetector = require('./localeDetector.cjs');
35
43
  var import_localeList = require('./localeList.cjs');
44
+ var import_localeMapper = require('./localeMapper.cjs');
36
45
  var import_localeResolver = require('./localeResolver.cjs');
37
- var import_localeDetector = require('./localeDetector.cjs');
38
- var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
39
- var import_getMultilingualUrls = require('./getMultilingualUrls.cjs');
40
- var import_getLocalizedUrl = require('./getLocalizedUrl.cjs');
41
46
  // Annotate the CommonJS export names for ESM import in node:
42
47
  0 && (module.exports = {
43
48
  getHTMLTextDir,
49
+ getLocaleFromPath,
44
50
  getLocaleLang,
45
51
  getLocaleName,
46
52
  getLocalizedUrl,
47
53
  getMultilingualUrls,
48
54
  getPathWithoutLocale,
49
55
  localeDetector,
56
+ localeFlatMap,
50
57
  localeList,
58
+ localeMap,
51
59
  localeResolver
52
60
  });
53
61
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getLocaleName } from './getLocaleName';\nexport { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleLang } from './getLocaleLang';\nexport { localeList } from './localeList';\nexport { localeResolver } from './localeResolver';\nexport { localeDetector } from './localeDetector';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getLocalizedUrl } from './getLocalizedUrl';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,4BAA+B;AAC/B,2BAA8B;AAC9B,wBAA2B;AAC3B,4BAA+B;AAC/B,4BAA+B;AAC/B,kCAAqC;AACrC,iCAAoC;AACpC,6BAAgC;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleFromPath } from './getLocaleFromPath';\nexport { getLocaleLang } from './getLocaleLang';\nexport { getLocaleName } from './getLocaleName';\nexport { getLocalizedUrl } from './getLocalizedUrl';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { localeDetector } from './localeDetector';\nexport { localeList } from './localeList';\nexport { localeFlatMap, localeMap } from './localeMapper';\nexport { localeResolver } from './localeResolver';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,+BAAkC;AAClC,2BAA8B;AAC9B,2BAA8B;AAC9B,6BAAgC;AAChC,iCAAoC;AACpC,kCAAqC;AACrC,4BAA+B;AAC/B,wBAA2B;AAC3B,0BAAyC;AACzC,4BAA+B;","names":[]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var localeMapper_exports = {};
30
+ __export(localeMapper_exports, {
31
+ localeFlatMap: () => localeFlatMap,
32
+ localeMap: () => localeMap
33
+ });
34
+ module.exports = __toCommonJS(localeMapper_exports);
35
+ var import_built = __toESM(require("@intlayer/config/built"));
36
+ const localeMap = (mapper, locales = import_built.default.internationalization.locales, defaultLocale = import_built.default.internationalization.defaultLocale, prefixDefault = import_built.default.middleware.prefixDefault) => locales.map(
37
+ (locale) => mapper({
38
+ locale,
39
+ defaultLocale,
40
+ locales,
41
+ isDefault: locale === defaultLocale,
42
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
43
+ })
44
+ );
45
+ const localeFlatMap = (mapper, locales = import_built.default.internationalization.locales, defaultLocale = import_built.default.internationalization.defaultLocale, prefixDefault = import_built.default.middleware.prefixDefault) => locales.flatMap(
46
+ (locale) => mapper({
47
+ locale,
48
+ defaultLocale,
49
+ locales,
50
+ isDefault: locale === defaultLocale,
51
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
52
+ })
53
+ );
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ localeFlatMap,
57
+ localeMap
58
+ });
59
+ //# sourceMappingURL=localeMapper.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { LocalesValues } from '@intlayer/config/client';\n\nexport type LocaleData = {\n locale: LocalesValues;\n defaultLocale: LocalesValues;\n isDefault: boolean;\n locales: LocalesValues[];\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 extends object>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale,\n prefixDefault: boolean = configuration.middleware.prefixDefault\n): T[] =>\n locales.map((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(\n mapper: (locale: LocaleData) => T[],\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale,\n prefixDefault: boolean = configuration.middleware.prefixDefault\n): T[] =>\n locales.flatMap((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAqCnB,MAAM,YAAY,CACvB,QACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,eACH,gBAAyB,aAAAA,QAAc,WAAW,kBAElD,QAAQ;AAAA,EAAI,CAAC,WACX,OAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;AA4BK,MAAM,gBAAgB,CAC3B,QACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,eACH,gBAAyB,aAAAA,QAAc,WAAW,kBAElD,QAAQ;AAAA,EAAQ,CAAC,WACf,OAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;","names":["configuration"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\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[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): LocalesValues => {\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 // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch;\n }\n\n // 2) 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 (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAMnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,kBACe;AAElB,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":["configuration"]}
1
+ {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\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[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): LocalesValues => {\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 // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch;\n }\n\n // 2) 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 (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAOnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,kBACe;AAElB,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":["configuration"]}
@@ -1,9 +1,9 @@
1
- export * from "./transpiler/index.mjs";
2
- export * from "./interpreter/index.mjs";
3
1
  export * from "./dictionaryManipulator/index.mjs";
2
+ export * from "./interpreter/index.mjs";
3
+ export * from "./localization/index.mjs";
4
+ export * from "./transpiler/index.mjs";
4
5
  export * from "./types/index.mjs";
5
- export * from "./utils/isSameKeyPath.mjs";
6
6
  export * from "./utils/checkIsURLAbsolute.mjs";
7
+ export * from "./utils/isSameKeyPath.mjs";
7
8
  export * from "./utils/isValidReactElement.mjs";
8
- export * from "./localization/index.mjs";
9
9
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './transpiler/index';\nexport * from './interpreter/index';\nexport * from './dictionaryManipulator/index';\nexport * from './types/index';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isValidReactElement';\nexport * from './localization/index';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,25 @@
1
+ import configuration from "@intlayer/config/built";
2
+ import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs";
3
+ const getLocaleFromPath = (inputUrl) => {
4
+ const { defaultLocale, locales } = configuration.internationalization;
5
+ const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);
6
+ let fixedInputUrl = inputUrl;
7
+ if (inputUrl.endsWith("/")) {
8
+ fixedInputUrl = inputUrl.slice(0, -1);
9
+ }
10
+ const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
11
+ const pathname = url.pathname;
12
+ if (!pathname.startsWith("/")) {
13
+ return defaultLocale;
14
+ }
15
+ const pathSegments = pathname.split("/");
16
+ const firstSegment = pathSegments[1];
17
+ if (firstSegment && locales.includes(firstSegment)) {
18
+ return firstSegment;
19
+ }
20
+ return defaultLocale;
21
+ };
22
+ export {
23
+ getLocaleFromPath
24
+ };
25
+ //# sourceMappingURL=getLocaleFromPath.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales } from '@intlayer/config/client';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Extracts the locale segment from the given URL or pathname if present.\n * If no locale is present, returns the default locale (en).\n *\n * Example:\n *\n * ```ts\n * getLocaleFromPath('/en/dashboard') // Returns 'en'\n * getLocaleFromPath('/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('/dashboard') // Returns 'en'\n * getLocaleFromPath('dashboard') // Returns 'en'\n * getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'\n * getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('https://example.com/dashboard') // Returns 'en'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @returns The detected locale or default (en) if no locale is found\n */\nexport const getLocaleFromPath = (inputUrl: string): Locales => {\n // Define supported locales array\n const { defaultLocale, locales } = configuration.internationalization;\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\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 url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the default locale\n return defaultLocale;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (firstSegment && locales.includes(firstSegment as Locales)) {\n // Return the detected locale\n return firstSegment as Locales;\n }\n\n // Return the default locale if no locale is found in the path\n return defaultLocale;\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAE1B,SAAS,0BAA0B;AAqB5B,MAAM,oBAAoB,CAAC,aAA8B;AAE9D,QAAM,EAAE,eAAe,QAAQ,IAAI,cAAc;AAGjD,QAAM,gBAAgB,mBAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,WAAO;AAAA,EACT;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,gBAAgB,QAAQ,SAAS,YAAuB,GAAG;AAE7D,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration.internationalization\n .locales as LocalesValues[]\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\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 url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales.includes(firstSegment as Locales)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAE1B,SAAS,0BAA0B;AAuB5B,MAAM,uBAAuB,CAClC,UACA,UAA2B,cAAc,qBACtC,YACQ;AAEX,QAAM,gBAAgB,mBAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,QAAI,WAAW,IAAI,QAAQ;AAAA,EAC7B;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,QAAQ,SAAS,YAAuB,GAAG;AAE7C,iBAAa,OAAO,GAAG,CAAC;AAGxB,UAAM,cAAc,aAAa,KAAK,GAAG,KAAK;AAC9C,QAAI,WAAW;AAAA,EACjB;AAEA,MAAI,eAAe;AAEjB,WAAO,IAAI,SAAS;AAAA,EACtB;AAGA,SAAO,IAAI,SAAS,EAAE,QAAQ,sBAAsB,EAAE;AACxD;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locales, type LocalesValues } from '@intlayer/config/client';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration.internationalization\n .locales as LocalesValues[]\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\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 url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales.includes(firstSegment as Locales)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAG1B,SAAS,0BAA0B;AAuB5B,MAAM,uBAAuB,CAClC,UACA,UAA2B,cAAc,qBACtC,YACQ;AAEX,QAAM,gBAAgB,mBAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,QAAI,WAAW,IAAI,QAAQ;AAAA,EAC7B;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,QAAQ,SAAS,YAAuB,GAAG;AAE7C,iBAAa,OAAO,GAAG,CAAC;AAGxB,UAAM,cAAc,aAAa,KAAK,GAAG,KAAK;AAC9C,QAAI,WAAW;AAAA,EACjB;AAEA,MAAI,eAAe;AAEjB,WAAO,IAAI,SAAS;AAAA,EACtB;AAGA,SAAO,IAAI,SAAS,EAAE,QAAQ,sBAAsB,EAAE;AACxD;","names":[]}
@@ -1,21 +1,26 @@
1
- import { getLocaleName } from "./getLocaleName.mjs";
2
1
  import { getHTMLTextDir } from "./getHTMLTextDir.mjs";
2
+ import { getLocaleFromPath } from "./getLocaleFromPath.mjs";
3
3
  import { getLocaleLang } from "./getLocaleLang.mjs";
4
+ import { getLocaleName } from "./getLocaleName.mjs";
5
+ import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
6
+ import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
7
+ import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
8
+ import { localeDetector } from "./localeDetector.mjs";
4
9
  import { localeList } from "./localeList.mjs";
10
+ import { localeFlatMap, localeMap } from "./localeMapper.mjs";
5
11
  import { localeResolver } from "./localeResolver.mjs";
6
- import { localeDetector } from "./localeDetector.mjs";
7
- import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
8
- import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
9
- import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
10
12
  export {
11
13
  getHTMLTextDir,
14
+ getLocaleFromPath,
12
15
  getLocaleLang,
13
16
  getLocaleName,
14
17
  getLocalizedUrl,
15
18
  getMultilingualUrls,
16
19
  getPathWithoutLocale,
17
20
  localeDetector,
21
+ localeFlatMap,
18
22
  localeList,
23
+ localeMap,
19
24
  localeResolver
20
25
  };
21
26
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getLocaleName } from './getLocaleName';\nexport { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleLang } from './getLocaleLang';\nexport { localeList } from './localeList';\nexport { localeResolver } from './localeResolver';\nexport { localeDetector } from './localeDetector';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getLocalizedUrl } from './getLocalizedUrl';\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleFromPath } from './getLocaleFromPath';\nexport { getLocaleLang } from './getLocaleLang';\nexport { getLocaleName } from './getLocaleName';\nexport { getLocalizedUrl } from './getLocalizedUrl';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { localeDetector } from './localeDetector';\nexport { localeList } from './localeList';\nexport { localeFlatMap, localeMap } from './localeMapper';\nexport { localeResolver } from './localeResolver';\n"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,eAAe,iBAAiB;AACzC,SAAS,sBAAsB;","names":[]}
@@ -0,0 +1,24 @@
1
+ import configuration from "@intlayer/config/built";
2
+ const localeMap = (mapper, locales = configuration.internationalization.locales, defaultLocale = configuration.internationalization.defaultLocale, prefixDefault = configuration.middleware.prefixDefault) => locales.map(
3
+ (locale) => mapper({
4
+ locale,
5
+ defaultLocale,
6
+ locales,
7
+ isDefault: locale === defaultLocale,
8
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
9
+ })
10
+ );
11
+ const localeFlatMap = (mapper, locales = configuration.internationalization.locales, defaultLocale = configuration.internationalization.defaultLocale, prefixDefault = configuration.middleware.prefixDefault) => locales.flatMap(
12
+ (locale) => mapper({
13
+ locale,
14
+ defaultLocale,
15
+ locales,
16
+ isDefault: locale === defaultLocale,
17
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
18
+ })
19
+ );
20
+ export {
21
+ localeFlatMap,
22
+ localeMap
23
+ };
24
+ //# sourceMappingURL=localeMapper.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { LocalesValues } from '@intlayer/config/client';\n\nexport type LocaleData = {\n locale: LocalesValues;\n defaultLocale: LocalesValues;\n isDefault: boolean;\n locales: LocalesValues[];\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 extends object>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale,\n prefixDefault: boolean = configuration.middleware.prefixDefault\n): T[] =>\n locales.map((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(\n mapper: (locale: LocaleData) => T[],\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale,\n prefixDefault: boolean = configuration.middleware.prefixDefault\n): T[] =>\n locales.flatMap((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n"],"mappings":"AAAA,OAAO,mBAAmB;AAqCnB,MAAM,YAAY,CACvB,QACA,UAA2B,cAAc,qBAAqB,SAC9D,gBAA+B,cAAc,qBAC1C,eACH,gBAAyB,cAAc,WAAW,kBAElD,QAAQ;AAAA,EAAI,CAAC,WACX,OAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;AA4BK,MAAM,gBAAgB,CAC3B,QACA,UAA2B,cAAc,qBAAqB,SAC9D,gBAA+B,cAAc,qBAC1C,eACH,gBAAyB,cAAc,WAAW,kBAElD,QAAQ;AAAA,EAAQ,CAAC,WACf,OAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\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[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): LocalesValues => {\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 // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch;\n }\n\n // 2) 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 (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAMnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,cAAc,qBAAqB,SAC9D,gBAA+B,cAAc,qBAC1C,kBACe;AAElB,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\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[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): LocalesValues => {\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 // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch;\n }\n\n // 2) 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 (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale;\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAOnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,cAAc,qBAAqB,SAC9D,gBAA+B,cAAc,qBAC1C,kBACe;AAElB,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":[]}
@@ -1,9 +1,9 @@
1
- export * from './transpiler/index';
2
- export * from './interpreter/index';
3
1
  export * from './dictionaryManipulator/index';
2
+ export * from './interpreter/index';
3
+ export * from './localization/index';
4
+ export * from './transpiler/index';
4
5
  export * from './types/index';
5
- export * from './utils/isSameKeyPath';
6
6
  export * from './utils/checkIsURLAbsolute';
7
+ export * from './utils/isSameKeyPath';
7
8
  export * from './utils/isValidReactElement';
8
- export * from './localization/index';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Locales } from '@intlayer/config/client';
2
+ /**
3
+ * Extracts the locale segment from the given URL or pathname if present.
4
+ * If no locale is present, returns the default locale (en).
5
+ *
6
+ * Example:
7
+ *
8
+ * ```ts
9
+ * getLocaleFromPath('/en/dashboard') // Returns 'en'
10
+ * getLocaleFromPath('/fr/dashboard') // Returns 'fr'
11
+ * getLocaleFromPath('/dashboard') // Returns 'en'
12
+ * getLocaleFromPath('dashboard') // Returns 'en'
13
+ * getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'
14
+ * getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'
15
+ * getLocaleFromPath('https://example.com/dashboard') // Returns 'en'
16
+ * ```
17
+ *
18
+ * @param inputUrl - The complete URL string or pathname to process.
19
+ * @returns The detected locale or default (en) if no locale is found
20
+ */
21
+ export declare const getLocaleFromPath: (inputUrl: string) => Locales;
22
+ //# sourceMappingURL=getLocaleFromPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocaleFromPath.d.ts","sourceRoot":"","sources":["../../../src/localization/getLocaleFromPath.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,KAAG,OAuCpD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getPathWithoutLocale.d.ts","sourceRoot":"","sources":["../../../src/localization/getPathWithoutLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAK3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,MAAM,EAChB,UAAS,aAAa,EACO,KAC5B,MA6CF,CAAC"}
1
+ {"version":3,"file":"getPathWithoutLocale.d.ts","sourceRoot":"","sources":["../../../src/localization/getPathWithoutLocale.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAI3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,MAAM,EAChB,UAAS,aAAa,EACO,KAC5B,MA6CF,CAAC"}
@@ -1,10 +1,12 @@
1
- export { getLocaleName } from './getLocaleName';
2
1
  export { getHTMLTextDir } from './getHTMLTextDir';
2
+ export { getLocaleFromPath } from './getLocaleFromPath';
3
3
  export { getLocaleLang } from './getLocaleLang';
4
+ export { getLocaleName } from './getLocaleName';
5
+ export { getLocalizedUrl } from './getLocalizedUrl';
6
+ export { getMultilingualUrls } from './getMultilingualUrls';
7
+ export { getPathWithoutLocale } from './getPathWithoutLocale';
8
+ export { localeDetector } from './localeDetector';
4
9
  export { localeList } from './localeList';
10
+ export { localeFlatMap, localeMap } from './localeMapper';
5
11
  export { localeResolver } from './localeResolver';
6
- export { localeDetector } from './localeDetector';
7
- export { getPathWithoutLocale } from './getPathWithoutLocale';
8
- export { getMultilingualUrls } from './getMultilingualUrls';
9
- export { getLocalizedUrl } from './getLocalizedUrl';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/localization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/localization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { LocalesValues } from '@intlayer/config/client';
2
+ export type LocaleData = {
3
+ locale: LocalesValues;
4
+ defaultLocale: LocalesValues;
5
+ isDefault: boolean;
6
+ locales: LocalesValues[];
7
+ urlPrefix: string;
8
+ };
9
+ /**
10
+ * Map the locale data to an array of objects
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const routes = localeMap((localizedData) =>
15
+ * ({
16
+ * path: localizedData.urlPrefix,
17
+ * name: localizedData.locale,
18
+ * isDefault: localizedData.isDefault,
19
+ * locales: localizedData.locales,
20
+ * defaultLocale: localizedData.defaultLocale,
21
+ * }),
22
+ * );
23
+ *
24
+ * // Result
25
+ * [
26
+ * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },
27
+ * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },
28
+ * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },
29
+ * ]
30
+ * ```
31
+ *
32
+ * @param mapper - The mapper function that returns an object
33
+ * @returns An array of objects
34
+ */
35
+ export declare const localeMap: <T extends object>(mapper: (locale: LocaleData) => T, locales?: LocalesValues[], defaultLocale?: LocalesValues, prefixDefault?: boolean) => T[];
36
+ /**
37
+ * Flatten the locale map into a single array of objects
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const routes = localeMap((localizedData) =>
42
+ * [{
43
+ * path: localizedData.urlPrefix,
44
+ * name: localizedData.locale,
45
+ * isDefault: localizedData.isDefault,
46
+ * locales: localizedData.locales,
47
+ * defaultLocale: localizedData.defaultLocale,
48
+ * }],
49
+ * );
50
+ *
51
+ * // Result
52
+ * [
53
+ * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },
54
+ * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },
55
+ * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },
56
+ * ]
57
+ * ```
58
+ *
59
+ * @param mapper - The mapper function that returns an array of objects
60
+ * @returns An array of objects
61
+ */
62
+ export declare const localeFlatMap: <T>(mapper: (locale: LocaleData) => T[], locales?: LocalesValues[], defaultLocale?: LocalesValues, prefixDefault?: boolean) => T[];
63
+ //# sourceMappingURL=localeMapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeMapper.d.ts","sourceRoot":"","sources":["../../../src/localization/localeMapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,aAAa,CAAC;IACtB,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EACxC,QAAQ,CAAC,MAAM,EAAE,UAAU,KAAK,CAAC,EACjC,UAAS,aAAa,EAA+C,EACrE,gBAAe,aACC,EAChB,gBAAe,OAAgD,KAC9D,CAAC,EASD,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,KAAK,CAAC,EAAE,EACnC,UAAS,aAAa,EAA+C,EACrE,gBAAe,aACC,EAChB,gBAAe,OAAgD,KAC9D,CAAC,EASD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"localeResolver.d.ts","sourceRoot":"","sources":["../../../src/localization/localeResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7D;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,gBAAgB,aAAa,GAAG,aAAa,EAAE,EAC/C,UAAS,aAAa,EAA+C,EACrE,gBAAe,aACC,KACf,aAqCF,CAAC"}
1
+ {"version":3,"file":"localeResolver.d.ts","sourceRoot":"","sources":["../../../src/localization/localeResolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,gBAAgB,aAAa,GAAG,aAAa,EAAE,EAC/C,UAAS,aAAa,EAA+C,EACrE,gBAAe,aACC,KACf,aAqCF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/core",
3
- "version": "5.3.13",
3
+ "version": "5.4.0",
4
4
  "private": false,
5
5
  "description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
6
6
  "keywords": [
@@ -75,9 +75,9 @@
75
75
  ],
76
76
  "dependencies": {
77
77
  "negotiator": "^1.0.0",
78
- "@intlayer/api": "5.3.13",
79
- "@intlayer/config": "5.3.13",
80
- "@intlayer/dictionaries-entry": "5.3.13"
78
+ "@intlayer/api": "5.4.0",
79
+ "@intlayer/config": "5.4.0",
80
+ "@intlayer/dictionaries-entry": "5.4.0"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@types/negotiator": "^0.6.3",
@@ -91,15 +91,15 @@
91
91
  "tsup": "^8.4.0",
92
92
  "typescript": "^5.8.2",
93
93
  "@utils/tsup-config": "1.0.4",
94
- "@utils/eslint-config": "1.0.4",
95
94
  "@utils/ts-config": "1.0.4",
95
+ "@utils/eslint-config": "1.0.4",
96
96
  "@utils/ts-config-types": "1.0.4"
97
97
  },
98
98
  "peerDependencies": {
99
- "@intlayer/api": "5.3.13",
100
- "@intlayer/config": "5.3.13",
101
- "@intlayer/dictionaries-entry": "5.3.13",
102
- "intlayer": "5.3.13"
99
+ "@intlayer/dictionaries-entry": "5.4.0",
100
+ "@intlayer/config": "5.4.0",
101
+ "@intlayer/api": "5.4.0",
102
+ "intlayer": "5.4.0"
103
103
  },
104
104
  "engines": {
105
105
  "node": ">=14.18"