next-intlayer 3.4.8 → 3.5.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 (73) hide show
  1. package/package.json +15 -15
  2. package/dist/cjs/client/IntlayerClientProvider.cjs +0 -36
  3. package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
  4. package/dist/cjs/client/index.cjs +0 -43
  5. package/dist/cjs/client/index.cjs.map +0 -1
  6. package/dist/cjs/client/useLocale.cjs +0 -101
  7. package/dist/cjs/client/useLocale.cjs.map +0 -1
  8. package/dist/cjs/generateStaticParams.cjs +0 -31
  9. package/dist/cjs/generateStaticParams.cjs.map +0 -1
  10. package/dist/cjs/index.cjs +0 -49
  11. package/dist/cjs/index.cjs.map +0 -1
  12. package/dist/cjs/middleware/index.cjs +0 -23
  13. package/dist/cjs/middleware/index.cjs.map +0 -1
  14. package/dist/cjs/middleware/intlayerMiddleware.cjs +0 -177
  15. package/dist/cjs/middleware/intlayerMiddleware.cjs.map +0 -1
  16. package/dist/cjs/middleware/localeDetector.cjs +0 -35
  17. package/dist/cjs/middleware/localeDetector.cjs.map +0 -1
  18. package/dist/cjs/server/index.cjs +0 -46
  19. package/dist/cjs/server/index.cjs.map +0 -1
  20. package/dist/cjs/server/withIntlayer.cjs +0 -83
  21. package/dist/cjs/server/withIntlayer.cjs.map +0 -1
  22. package/dist/cjs/types/NextPage.cjs +0 -17
  23. package/dist/cjs/types/NextPage.cjs.map +0 -1
  24. package/dist/cjs/types/index.cjs +0 -17
  25. package/dist/cjs/types/index.cjs.map +0 -1
  26. package/dist/esm/client/IntlayerClientProvider.mjs +0 -12
  27. package/dist/esm/client/IntlayerClientProvider.mjs.map +0 -1
  28. package/dist/esm/client/index.mjs +0 -21
  29. package/dist/esm/client/index.mjs.map +0 -1
  30. package/dist/esm/client/useLocale.mjs +0 -77
  31. package/dist/esm/client/useLocale.mjs.map +0 -1
  32. package/dist/esm/generateStaticParams.mjs +0 -7
  33. package/dist/esm/generateStaticParams.mjs.map +0 -1
  34. package/dist/esm/index.mjs +0 -27
  35. package/dist/esm/index.mjs.map +0 -1
  36. package/dist/esm/middleware/index.mjs +0 -2
  37. package/dist/esm/middleware/index.mjs.map +0 -1
  38. package/dist/esm/middleware/intlayerMiddleware.mjs +0 -155
  39. package/dist/esm/middleware/intlayerMiddleware.mjs.map +0 -1
  40. package/dist/esm/middleware/localeDetector.mjs +0 -11
  41. package/dist/esm/middleware/localeDetector.mjs.map +0 -1
  42. package/dist/esm/server/index.mjs +0 -23
  43. package/dist/esm/server/index.mjs.map +0 -1
  44. package/dist/esm/server/withIntlayer.mjs +0 -59
  45. package/dist/esm/server/withIntlayer.mjs.map +0 -1
  46. package/dist/esm/types/NextPage.mjs +0 -1
  47. package/dist/esm/types/NextPage.mjs.map +0 -1
  48. package/dist/esm/types/index.mjs +0 -1
  49. package/dist/esm/types/index.mjs.map +0 -1
  50. package/dist/types/client/IntlayerClientProvider.d.ts +0 -5
  51. package/dist/types/client/IntlayerClientProvider.d.ts.map +0 -1
  52. package/dist/types/client/index.d.ts +0 -4
  53. package/dist/types/client/index.d.ts.map +0 -1
  54. package/dist/types/client/useLocale.d.ts +0 -10
  55. package/dist/types/client/useLocale.d.ts.map +0 -1
  56. package/dist/types/generateStaticParams.d.ts +0 -4
  57. package/dist/types/generateStaticParams.d.ts.map +0 -1
  58. package/dist/types/index.d.ts +0 -5
  59. package/dist/types/index.d.ts.map +0 -1
  60. package/dist/types/middleware/index.d.ts +0 -2
  61. package/dist/types/middleware/index.d.ts.map +0 -1
  62. package/dist/types/middleware/intlayerMiddleware.d.ts +0 -26
  63. package/dist/types/middleware/intlayerMiddleware.d.ts.map +0 -1
  64. package/dist/types/middleware/localeDetector.d.ts +0 -9
  65. package/dist/types/middleware/localeDetector.d.ts.map +0 -1
  66. package/dist/types/server/index.d.ts +0 -3
  67. package/dist/types/server/index.d.ts.map +0 -1
  68. package/dist/types/server/withIntlayer.d.ts +0 -15
  69. package/dist/types/server/withIntlayer.d.ts.map +0 -1
  70. package/dist/types/types/NextPage.d.ts +0 -18
  71. package/dist/types/types/NextPage.d.ts.map +0 -1
  72. package/dist/types/types/index.d.ts +0 -2
  73. package/dist/types/types/index.d.ts.map +0 -1
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var server_exports = {};
20
- __export(server_exports, {
21
- IntlayerServer: () => import_server.IntlayerServer,
22
- IntlayerServerProvider: () => import_server.IntlayerServerProvider,
23
- getLocaleContent: () => import_server.getLocaleContent,
24
- locale: () => import_server.locale,
25
- t: () => import_server.t,
26
- useDictionary: () => import_server.useDictionary,
27
- useIntlayer: () => import_server.useIntlayer,
28
- useTraduction: () => import_server.useTraduction,
29
- withIntlayer: () => import_withIntlayer.withIntlayer
30
- });
31
- module.exports = __toCommonJS(server_exports);
32
- var import_server = require("react-intlayer/server");
33
- var import_withIntlayer = require('./withIntlayer.cjs');
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- IntlayerServer,
37
- IntlayerServerProvider,
38
- getLocaleContent,
39
- locale,
40
- t,
41
- useDictionary,
42
- useIntlayer,
43
- useTraduction,
44
- withIntlayer
45
- });
46
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n getLocaleContent,\n useDictionary,\n useTraduction,\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n useIntlayer,\n t,\n} from 'react-intlayer/server';\nexport { withIntlayer } from './withIntlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBASO;AACP,0BAA6B;","names":[]}
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var withIntlayer_exports = {};
20
- __export(withIntlayer_exports, {
21
- withIntlayer: () => withIntlayer
22
- });
23
- module.exports = __toCommonJS(withIntlayer_exports);
24
- var import_path = require("path");
25
- var import_config = require("@intlayer/config");
26
- var import_webpack = require("@intlayer/webpack");
27
- const withIntlayer = (nextConfig = {}) => {
28
- if (typeof nextConfig !== "object") nextConfig = {};
29
- const intlayerConfig = (0, import_config.getConfiguration)();
30
- const env = (0, import_config.formatEnvVariable)("next");
31
- const { mainDir, baseDir } = intlayerConfig.content;
32
- const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
33
- const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
34
- return Object.assign({}, nextConfig, {
35
- env: { ...nextConfig.env, ...env },
36
- experimental: {
37
- ...nextConfig.experimental ?? {},
38
- // Using Intlayer with Turbopack is not supported as long external modules can't be resolved (such as esbuild or fs)
39
- turbo: {
40
- ...nextConfig.experimental?.turbo ?? {},
41
- resolveAlias: {
42
- ...nextConfig.experimental?.turbo?.resolveAlias ?? {},
43
- "@intlayer/dictionaries-entry": (0, import_path.resolve)(relativeDictionariesPath)
44
- },
45
- rules: {
46
- "*.node": {
47
- as: "*.node",
48
- loaders: ["node-loader"]
49
- }
50
- }
51
- }
52
- },
53
- webpack: (config, options) => {
54
- if (nextConfig.webpack) {
55
- config = nextConfig.webpack(config, options);
56
- }
57
- config.resolve.alias["@intlayer/dictionaries-entry"] = (0, import_path.resolve)(
58
- relativeDictionariesPath
59
- );
60
- config.externals.push({
61
- esbuild: "esbuild",
62
- module: "module",
63
- fs: "fs",
64
- chokidar: "chokidar",
65
- fsevents: "fsevents"
66
- });
67
- config.module.rules.push({
68
- test: /\.node$/,
69
- loader: "node-loader"
70
- });
71
- const { isServer, nextRuntime } = options;
72
- if (isServer && nextRuntime === "nodejs") {
73
- config.plugins.push(new import_webpack.IntLayerPlugin());
74
- }
75
- return config;
76
- }
77
- });
78
- };
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {
81
- withIntlayer
82
- });
83
- //# sourceMappingURL=withIntlayer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { IntLayerPlugin } from '@intlayer/webpack';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n */\nexport const withIntlayer = (\n nextConfig: Partial<NextConfig> = {}\n): Partial<NextConfig> => {\n if (typeof nextConfig !== 'object') nextConfig = {};\n\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('next');\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return Object.assign({}, nextConfig, {\n env: { ...nextConfig.env, ...env },\n\n experimental: {\n ...(nextConfig.experimental ?? {}),\n // Using Intlayer with Turbopack is not supported as long external modules can't be resolved (such as esbuild or fs)\n turbo: {\n ...(nextConfig.experimental?.turbo ?? {}),\n resolveAlias: {\n ...(nextConfig.experimental?.turbo?.resolveAlias ?? {}),\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n },\n },\n\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n if (nextConfig.webpack) {\n // Invoke the existing webpack config if it exists\n config = nextConfig.webpack(config, options);\n }\n\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n const { isServer, nextRuntime } = options;\n\n // Apply IntLayerPlugin only on the server-side\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntLayerPlugin());\n }\n\n return config;\n },\n } satisfies Partial<NextConfig>);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwC;AACxC,oBAAoD;AACpD,qBAA+B;AAkBxB,MAAM,eAAe,CAC1B,aAAkC,CAAC,MACX;AACxB,MAAI,OAAO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F,CAA+B;AACjC;","names":[]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var NextPage_exports = {};
16
- module.exports = __toCommonJS(NextPage_exports);
17
- //# sourceMappingURL=NextPage.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/types/NextPage.ts"],"sourcesContent":["import type { Locales } from 'intlayer';\nimport type { NextPage } from 'next';\nimport type { PropsWithChildren } from 'react';\n\nexport type LocalParams<T = undefined> = {\n params: { locale: Locales } & T;\n};\n\nexport type LocalPromiseParams<T = undefined> = {\n params: Promise<{ locale: Locales } & T>;\n};\n\nexport type Next14PageIntlayer<T = undefined> = NextPage<LocalParams<T>>;\nexport type Next15PageIntlayer<T = undefined> = NextPage<LocalPromiseParams<T>>;\nexport type NextPageIntlayer<T = undefined> = Next15PageIntlayer<T>;\nexport type NextLayoutIntlayer<T = undefined> = NextPage<\n PropsWithChildren<LocalParams<T>>\n>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
17
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n LocalParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n NextLayoutIntlayer,\n LocalPromiseParams,\n} from './NextPage';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,12 +0,0 @@
1
- "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { IntlayerProvider } from "react-intlayer";
4
- import { useLocale } from './useLocale.mjs';
5
- const IntlayerClientProvider = (props) => {
6
- const { setLocale } = useLocale();
7
- return /* @__PURE__ */ jsx(IntlayerProvider, { setLocale, ...props });
8
- };
9
- export {
10
- IntlayerClientProvider
11
- };
12
- //# sourceMappingURL=IntlayerClientProvider.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\nimport { useLocale } from './useLocale';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => {\n const { setLocale } = useLocale();\n return <IntlayerProvider setLocale={setLocale} {...props} />;\n};\n"],"mappings":";AAUS;AAPT,SAAS,wBAAoD;AAC7D,SAAS,iBAAiB;AAInB,MAAM,yBAAoD,CAAC,UAAU;AAC1E,QAAM,EAAE,UAAU,IAAI,UAAU;AAChC,SAAO,oBAAC,oBAAiB,WAAuB,GAAG,OAAO;AAC5D;","names":[]}
@@ -1,21 +0,0 @@
1
- import {
2
- getTranslation,
3
- IntlayerClientContext,
4
- useIntlayer,
5
- useTraduction,
6
- useLocaleCookie
7
- } from "react-intlayer";
8
- import { useLocale } from './useLocale.mjs';
9
- import {
10
- IntlayerClientProvider
11
- } from './IntlayerClientProvider.mjs';
12
- export {
13
- IntlayerClientContext,
14
- IntlayerClientProvider,
15
- getTranslation,
16
- useIntlayer,
17
- useLocale,
18
- useLocaleCookie,
19
- useTraduction
20
- };
21
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n getTranslation,\n IntlayerClientContext,\n useIntlayer,\n useTraduction,\n useLocaleCookie,\n} from 'react-intlayer';\nexport { useLocale } from './useLocale';\nexport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './IntlayerClientProvider';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,OAEK;","names":[]}
@@ -1,77 +0,0 @@
1
- import { getConfiguration } from "@intlayer/config/client";
2
- import { usePathname, useRouter } from "next/navigation.js";
3
- import { useCallback } from "react";
4
- import { useLocaleCookie, useLocaleBase } from "react-intlayer";
5
- const useLocale = () => {
6
- const {
7
- /**
8
- * Prefix default prefix the default locale to the path as other locales.
9
- *
10
- * Example with prefixDefault = true and defaultLocale = 'en':
11
- * path = /en/dashboard or /fr/dashboard
12
- *
13
- * Example with prefixDefault = false and defaultLocale = 'en':
14
- * path = /dashboard or /fr/dashboard
15
- *
16
- */
17
- prefixDefault
18
- } = getConfiguration().middleware;
19
- const { setLocaleCookie } = useLocaleCookie();
20
- const reactLocaleHook = useLocaleBase();
21
- const { push, refresh } = useRouter();
22
- const pathname = usePathname();
23
- const {
24
- defaultLocale,
25
- availableLocales,
26
- locale: currentLocale,
27
- setLocale: setLocaleState
28
- } = reactLocaleHook;
29
- const getPathWithoutLocale = () => {
30
- if (
31
- // If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path
32
- !prefixDefault && currentLocale.toString() === defaultLocale.toString()
33
- ) {
34
- return pathname;
35
- }
36
- const slicedPath = pathname.slice(`/${currentLocale}`.length);
37
- if (slicedPath) {
38
- return slicedPath;
39
- }
40
- return "/";
41
- };
42
- const pathWithoutLocale = getPathWithoutLocale();
43
- const setLocale = useCallback(
44
- (locale) => {
45
- if (!availableLocales.includes(locale)) {
46
- console.error(`Locale ${locale} is not available`);
47
- return;
48
- }
49
- setLocaleCookie(locale);
50
- setLocaleState(locale);
51
- if (!prefixDefault && locale.toString() === defaultLocale.toString()) {
52
- push(pathWithoutLocale);
53
- } else {
54
- push(`/${locale}${pathWithoutLocale}`);
55
- }
56
- return refresh();
57
- },
58
- [
59
- currentLocale,
60
- availableLocales,
61
- setLocaleCookie,
62
- setLocaleState,
63
- prefixDefault,
64
- defaultLocale,
65
- pathWithoutLocale
66
- ]
67
- );
68
- return {
69
- ...reactLocaleHook,
70
- setLocale,
71
- pathWithoutLocale
72
- };
73
- };
74
- export {
75
- useLocale
76
- };
77
- //# sourceMappingURL=useLocale.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback } from 'react';\nimport { useLocaleCookie, useLocaleBase } from 'react-intlayer';\n\nexport const useLocale = () => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { setLocaleCookie } = useLocaleCookie();\n const reactLocaleHook = useLocaleBase();\n const { push, refresh } = useRouter();\n const pathname = usePathname();\n\n const {\n defaultLocale,\n availableLocales,\n locale: currentLocale,\n setLocale: setLocaleState,\n } = reactLocaleHook;\n\n const getPathWithoutLocale = () => {\n if (\n // If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path\n !prefixDefault &&\n currentLocale.toString() === defaultLocale.toString()\n ) {\n return pathname;\n }\n\n const slicedPath = pathname.slice(`/${currentLocale}`.length);\n\n // If the path without locale is not empty, we return it\n if (slicedPath) {\n return slicedPath;\n }\n\n // If the path without locale is empty, we return the root path\n return '/';\n };\n\n const pathWithoutLocale = getPathWithoutLocale();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleCookie(locale);\n setLocaleState(locale);\n\n if (!prefixDefault && locale.toString() === defaultLocale.toString()) {\n push(pathWithoutLocale);\n } else {\n push(`/${locale}${pathWithoutLocale}`);\n }\n\n return refresh();\n },\n [\n currentLocale,\n availableLocales,\n setLocaleCookie,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n pathWithoutLocale,\n ]\n );\n\n return {\n ...reactLocaleHook,\n setLocale,\n pathWithoutLocale,\n };\n};\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAC/C,SAAS,aAAa,iBAAiB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,qBAAqB;AAExC,MAAM,YAAY,MAAM;AAC7B,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,IAAI,iBAAiB,EAAE;AACvB,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAC5C,QAAM,kBAAkB,cAAc;AACtC,QAAM,EAAE,MAAM,QAAQ,IAAI,UAAU;AACpC,QAAM,WAAW,YAAY;AAE7B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,WAAW;AAAA,EACb,IAAI;AAEJ,QAAM,uBAAuB,MAAM;AACjC;AAAA;AAAA,MAEE,CAAC,iBACD,cAAc,SAAS,MAAM,cAAc,SAAS;AAAA,MACpD;AACA,aAAO;AAAA,IACT;AAEA,UAAM,aAAa,SAAS,MAAM,IAAI,aAAa,GAAG,MAAM;AAG5D,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAGA,WAAO;AAAA,EACT;AAEA,QAAM,oBAAoB,qBAAqB;AAE/C,QAAM,YAAY;AAAA,IAChB,CAAC,WAAoB;AACnB,UAAI,CAAC,iBAAiB,SAAS,MAAM,GAAG;AACtC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,sBAAgB,MAAM;AACtB,qBAAe,MAAM;AAErB,UAAI,CAAC,iBAAiB,OAAO,SAAS,MAAM,cAAc,SAAS,GAAG;AACpE,aAAK,iBAAiB;AAAA,MACxB,OAAO;AACL,aAAK,IAAI,MAAM,GAAG,iBAAiB,EAAE;AAAA,MACvC;AAEA,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,7 +0,0 @@
1
- import { getConfiguration } from "@intlayer/config/client";
2
- const { locales } = getConfiguration().internationalization;
3
- const generateStaticParams = () => locales.map((locale) => ({ locale }));
4
- export {
5
- generateStaticParams
6
- };
7
- //# sourceMappingURL=generateStaticParams.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\n\nconst { locales } = getConfiguration().internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,MAAM,EAAE,QAAQ,IAAI,iBAAiB,EAAE;AAEhC,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":[]}
@@ -1,27 +0,0 @@
1
- import {
2
- getTranslation,
3
- IntlayerClientContext,
4
- useIntlayer,
5
- useTraduction,
6
- useDictionary,
7
- useLocaleCookie,
8
- t
9
- } from "react-intlayer";
10
- import { generateStaticParams } from './generateStaticParams.mjs';
11
- import {
12
- useLocale,
13
- IntlayerClientProvider
14
- } from './client/index.mjs';
15
- export {
16
- IntlayerClientContext,
17
- IntlayerClientProvider,
18
- generateStaticParams,
19
- getTranslation,
20
- t,
21
- useDictionary,
22
- useIntlayer,
23
- useLocale,
24
- useLocaleCookie,
25
- useTraduction
26
- };
27
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getTranslation,\n IntlayerClientContext,\n useIntlayer,\n useTraduction,\n useDictionary,\n useLocaleCookie,\n type IntlayerNode,\n t,\n} from 'react-intlayer';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n NextLayoutIntlayer,\n LocalPromiseParams,\n} from './types/index';\nexport {\n useLocale,\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './client/index';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,4BAA4B;AASrC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;","names":[]}
@@ -1,2 +0,0 @@
1
- export * from './intlayerMiddleware.mjs';
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/middleware/index.ts"],"sourcesContent":["export * from './intlayerMiddleware';\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -1,155 +0,0 @@
1
- import { getConfiguration } from "@intlayer/config/client";
2
- import {
3
- NextResponse
4
- } from "next/server";
5
- import { localeDetector } from './localeDetector.mjs';
6
- const { internationalization, middleware } = getConfiguration();
7
- const { locales, defaultLocale } = internationalization;
8
- const {
9
- headerName,
10
- cookieName,
11
- prefixDefault,
12
- basePath,
13
- serverSetCookie,
14
- noPrefix
15
- } = middleware;
16
- const intlayerMiddleware = (request, _event, _response) => {
17
- const pathname = request.nextUrl.pathname;
18
- const cookieLocale = getCookieLocale(request);
19
- const basePathTrailingSlash = basePath.endsWith("/");
20
- if (noPrefix) {
21
- return handleNoPrefix(
22
- request,
23
- cookieLocale,
24
- pathname,
25
- basePathTrailingSlash
26
- );
27
- }
28
- const pathLocale = getPathLocale(pathname);
29
- return handlePrefix(
30
- request,
31
- cookieLocale,
32
- pathLocale,
33
- pathname,
34
- basePathTrailingSlash
35
- );
36
- };
37
- const getCookieLocale = (request) => {
38
- if (!cookieName) return void 0;
39
- const cookieValue = request.cookies.get(cookieName)?.value;
40
- if (cookieValue && locales.includes(cookieValue)) {
41
- return cookieValue;
42
- }
43
- };
44
- const handleNoPrefix = (request, cookieLocale, pathname, basePathTrailingSlash) => {
45
- const locale = cookieLocale ?? defaultLocale;
46
- const newPath = constructPath(
47
- locale,
48
- pathname,
49
- basePath,
50
- basePathTrailingSlash
51
- );
52
- return rewriteUrl(request, newPath, locale);
53
- };
54
- const getPathLocale = (pathname) => locales.find(
55
- (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
56
- );
57
- const handlePrefix = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
58
- if (!pathLocale) {
59
- return handleMissingPathLocale(
60
- request,
61
- cookieLocale,
62
- pathname,
63
- basePathTrailingSlash
64
- );
65
- }
66
- return handleExistingPathLocale(
67
- request,
68
- cookieLocale,
69
- pathLocale,
70
- pathname,
71
- basePathTrailingSlash
72
- );
73
- };
74
- const handleMissingPathLocale = (request, cookieLocale, pathname, basePathTrailingSlash) => {
75
- let locale = cookieLocale ?? localeDetector?.(request) ?? defaultLocale;
76
- if (!locales.includes(locale)) {
77
- console.warn(
78
- "The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale."
79
- );
80
- locale = defaultLocale;
81
- }
82
- const newPath = constructPath(
83
- locale,
84
- pathname,
85
- basePath,
86
- basePathTrailingSlash
87
- );
88
- return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, newPath, locale);
89
- };
90
- const handleExistingPathLocale = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
91
- if (
92
- // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie
93
- cookieLocale && cookieLocale !== pathLocale && serverSetCookie !== "always"
94
- ) {
95
- const newPath = handleCookieLocaleMismatch(
96
- request,
97
- pathname,
98
- pathLocale,
99
- cookieLocale,
100
- basePath,
101
- basePathTrailingSlash
102
- );
103
- return redirectUrl(request, newPath);
104
- }
105
- return handleDefaultLocaleRedirect(
106
- request,
107
- pathLocale,
108
- pathname,
109
- basePathTrailingSlash
110
- );
111
- };
112
- const handleCookieLocaleMismatch = (request, pathname, pathLocale, cookieLocale, basePath2, basePathTrailingSlash) => {
113
- const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);
114
- return constructPath(
115
- cookieLocale,
116
- newPath,
117
- basePath2,
118
- basePathTrailingSlash,
119
- request.nextUrl.search
120
- );
121
- };
122
- const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrailingSlash) => {
123
- if (
124
- // If default locale should not be prefixed and the pathLocale is the defaultLocale
125
- !prefixDefault && pathLocale === defaultLocale
126
- ) {
127
- let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
128
- if (basePathTrailingSlash) {
129
- pathWithoutLocale = pathWithoutLocale.slice(1);
130
- }
131
- if (request.nextUrl.search) {
132
- pathWithoutLocale += request.nextUrl.search;
133
- }
134
- return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);
135
- }
136
- return rewriteUrl(request, pathname, pathLocale);
137
- };
138
- const constructPath = (locale, path, basePath2, basePathTrailingSlash, search) => {
139
- let newPath = `${locale}${path}`;
140
- newPath = `${basePath2}${basePathTrailingSlash ? "" : "/"}${newPath}`;
141
- if (search) {
142
- newPath += search;
143
- }
144
- return newPath;
145
- };
146
- const rewriteUrl = (request, newPath, locale) => {
147
- const response = NextResponse.rewrite(new URL(newPath, request.url));
148
- response.headers.set(headerName, locale);
149
- return response;
150
- };
151
- const redirectUrl = (request, newPath) => NextResponse.redirect(new URL(newPath, request.url));
152
- export {
153
- intlayerMiddleware
154
- };
155
- //# sourceMappingURL=intlayerMiddleware.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\nconst { internationalization, middleware } = getConfiguration();\nconst { locales, defaultLocale } = internationalization;\nconst {\n headerName,\n cookieName,\n prefixDefault,\n basePath,\n serverSetCookie,\n noPrefix,\n} = middleware;\n\n/**\n * Middleware that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/middleware.ts\n *\n * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';\n *\n * // applies this middleware only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main middleware function for handling internationalization.\n *\n * @param request - The incoming Next.js request object.\n * @param event - The Next.js fetch event (optional).\n * @param response - The Next.js response object (optional).\n * @returns - The response to be returned to the client.\n */\nexport const intlayerMiddleware = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n const pathname = request.nextUrl.pathname;\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (\n noPrefix // If the application is configured not to use locale prefixes in URLs\n ) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\n/**\n * Retrieves the locale from the request cookies if available and valid.\n *\n * @param request - The incoming Next.js request object.\n * @returns - The locale found in the cookies, or undefined if not found or invalid.\n */\nconst getCookieLocale = (request: NextRequest): Locales | undefined => {\n if (!cookieName) return undefined;\n const cookieValue = request.cookies.get(cookieName)?.value as Locales;\n if (cookieValue && locales.includes(cookieValue)) {\n return cookieValue;\n }\n};\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The rewritten response with the locale applied.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n const locale = cookieLocale ?? defaultLocale;\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash\n );\n return rewriteUrl(request, newPath, locale);\n};\n\n/**\n * Extracts the locale from the URL pathname if present.\n *\n * @param pathname - The pathname from the request URL.\n * @returns - The locale found in the pathname, or undefined if not found.\n */\nconst getPathLocale = (pathname: string): Locales | undefined =>\n locales.find(\n (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`\n );\n\n/**\n * Handles the case where URLs have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handlePrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n !pathLocale // If the URL does not contain a locale prefix\n ) {\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n // If the URL contains a locale prefix\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\n/**\n * Handles requests where the locale is missing from the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handleMissingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n let locale = cookieLocale ?? localeDetector?.(request) ?? defaultLocale;\n if (!locales.includes(locale)) {\n console.warn(\n 'The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale.'\n );\n locale = defaultLocale;\n }\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash\n );\n\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\n};\n\n/**\n * Handles requests where the locale exists in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie\n cookieLocale &&\n cookieLocale !== pathLocale &&\n serverSetCookie !== 'always'\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n cookieLocale,\n basePath,\n basePathTrailingSlash\n );\n return redirectUrl(request, newPath);\n }\n\n // If the cookie locale matches the path locale, or cookie locale is not set, or serverSetCookie is 'always'\n return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\n/**\n * Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param pathname - The pathname from the request URL.\n * @param pathLocale - The locale extracted from the pathname.\n * @param cookieLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The new URL path with the correct locale.\n */\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n pathname: string,\n pathLocale: Locales,\n cookieLocale: Locales,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n // Replace the pathLocale in the pathname with the cookieLocale\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n};\n\n/**\n * Handles redirection when the default locale is used and prefixing is not required.\n *\n * @param request - The incoming Next.js request object.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The rewritten response without the locale prefix.\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If default locale should not be prefixed and the pathLocale is the defaultLocale\n !prefixDefault &&\n pathLocale === defaultLocale\n ) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || '/';\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n\n // If prefixing default locale is required or pathLocale is not the defaultLocale\n\n return rewriteUrl(request, pathname, pathLocale);\n};\n\n/**\n * Constructs a new path by combining the locale, path, basePath, and search parameters.\n *\n * @param locale - The locale to include in the path.\n * @param path - The original path from the request.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locales,\n path: string,\n basePath: string,\n basePathTrailingSlash: boolean,\n search?: string\n): string => {\n let newPath = `${locale}${path}`;\n\n newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${newPath}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\n\n/**\n * Rewrites the URL to the new path and sets the locale header.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to rewrite to.\n * @param locale - The locale to set in the response header.\n * @returns - The rewritten response.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locales\n): NextResponse => {\n const response = NextResponse.rewrite(new URL(newPath, request.url));\n response.headers.set(headerName, locale);\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @returns - The redirect response.\n */\nconst redirectUrl = (request: NextRequest, newPath: string): NextResponse =>\n NextResponse.redirect(new URL(newPath, request.url));\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAC/C;AAAA,EAGE;AAAA,OACK;AACP,SAAS,sBAAsB;AAE/B,MAAM,EAAE,sBAAsB,WAAW,IAAI,iBAAiB;AAC9D,MAAM,EAAE,SAAS,cAAc,IAAI;AACnC,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI;AAyBG,MAAM,qBAAqB,CAChC,SACA,QACA,cACiB;AACjB,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,eAAe,gBAAgB,OAAO;AAC5C,QAAM,wBAAwB,SAAS,SAAS,GAAG;AAEnD,MACE,UACA;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA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I,IAAI,SAAS,QAAQ,GAAG,CAAC;AACnE,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YACzC,aAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;","names":["basePath"]}
@@ -1,11 +0,0 @@
1
- import { localeDetector as localeDetectorCore } from "@intlayer/core";
2
- const localeDetector = (request) => {
3
- const negotiatorHeaders = {};
4
- request.headers.forEach((value, key) => negotiatorHeaders[key] = value);
5
- const locale = localeDetectorCore(negotiatorHeaders);
6
- return locale;
7
- };
8
- export {
9
- localeDetector
10
- };
11
- //# sourceMappingURL=localeDetector.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/middleware/localeDetector.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): Locales => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":"AACA,SAAS,kBAAkB,0BAA0B;AAQ9C,MAAM,iBAAiB,CAAC,YAAkC;AAC/D,QAAM,oBAA4C,CAAC;AAEnD,UAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAS,kBAAkB,GAAG,IAAI,KAAM;AAExE,QAAM,SAAS,mBAAmB,iBAAiB;AAEnD,SAAO;AACT;","names":[]}
@@ -1,23 +0,0 @@
1
- import {
2
- getLocaleContent,
3
- useDictionary,
4
- useTraduction,
5
- IntlayerServer,
6
- IntlayerServerProvider,
7
- locale,
8
- useIntlayer,
9
- t
10
- } from "react-intlayer/server";
11
- import { withIntlayer } from './withIntlayer.mjs';
12
- export {
13
- IntlayerServer,
14
- IntlayerServerProvider,
15
- getLocaleContent,
16
- locale,
17
- t,
18
- useDictionary,
19
- useIntlayer,
20
- useTraduction,
21
- withIntlayer
22
- };
23
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n getLocaleContent,\n useDictionary,\n useTraduction,\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n useIntlayer,\n t,\n} from 'react-intlayer/server';\nexport { withIntlayer } from './withIntlayer';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;","names":[]}