@intlayer/next-intl 9.0.0-canary.1 → 9.0.0-canary.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/NextIntlClientProvider.cjs +8 -3
- package/dist/cjs/client/NextIntlClientProvider.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +56 -13
- package/dist/cjs/index.cjs +92 -15
- package/dist/cjs/server/getLocale.cjs +15 -1
- package/dist/cjs/server/getLocale.cjs.map +1 -1
- package/dist/cjs/server/getRequestConfig.cjs +28 -0
- package/dist/cjs/server/getRequestConfig.cjs.map +1 -0
- package/dist/cjs/server/getTranslations.cjs +9 -4
- package/dist/cjs/server/getTranslations.cjs.map +1 -1
- package/dist/cjs/server/helpers.cjs +5 -3
- package/dist/cjs/server/helpers.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +5 -1
- package/dist/cjs/server/requestLocaleCache.cjs +36 -0
- package/dist/cjs/server/requestLocaleCache.cjs.map +1 -0
- package/dist/cjs/server/setRequestLocale.cjs +33 -0
- package/dist/cjs/server/setRequestLocale.cjs.map +1 -0
- package/dist/esm/client/NextIntlClientProvider.mjs +9 -4
- package/dist/esm/client/NextIntlClientProvider.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -4
- package/dist/esm/index.mjs +3 -6
- package/dist/esm/server/getLocale.mjs +15 -1
- package/dist/esm/server/getLocale.mjs.map +1 -1
- package/dist/esm/server/getRequestConfig.mjs +25 -0
- package/dist/esm/server/getRequestConfig.mjs.map +1 -0
- package/dist/esm/server/getTranslations.mjs +8 -4
- package/dist/esm/server/getTranslations.mjs.map +1 -1
- package/dist/esm/server/helpers.mjs +4 -3
- package/dist/esm/server/helpers.mjs.map +1 -1
- package/dist/esm/server/index.mjs +3 -1
- package/dist/esm/server/requestLocaleCache.mjs +33 -0
- package/dist/esm/server/requestLocaleCache.mjs.map +1 -0
- package/dist/esm/server/setRequestLocale.mjs +32 -0
- package/dist/esm/server/setRequestLocale.mjs.map +1 -0
- package/dist/types/client/NextIntlClientProvider.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -4
- package/dist/types/index.d.ts +3 -6
- package/dist/types/server/getLocale.d.ts +9 -0
- package/dist/types/server/getLocale.d.ts.map +1 -1
- package/dist/types/server/getRequestConfig.d.ts +19 -0
- package/dist/types/server/getRequestConfig.d.ts.map +1 -0
- package/dist/types/server/getTranslations.d.ts +7 -29
- package/dist/types/server/getTranslations.d.ts.map +1 -1
- package/dist/types/server/helpers.d.ts +2 -1
- package/dist/types/server/helpers.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +3 -1
- package/dist/types/server/requestLocaleCache.d.ts +17 -0
- package/dist/types/server/requestLocaleCache.d.ts.map +1 -0
- package/dist/types/server/setRequestLocale.d.ts +29 -0
- package/dist/types/server/setRequestLocale.d.ts.map +1 -0
- package/package.json +10 -9
- package/dist/cjs/client/helpers.cjs +0 -66
- package/dist/cjs/client/helpers.cjs.map +0 -1
- package/dist/cjs/client/useTranslations.cjs +0 -39
- package/dist/cjs/client/useTranslations.cjs.map +0 -1
- package/dist/cjs/createFormatter.cjs +0 -59
- package/dist/cjs/createFormatter.cjs.map +0 -1
- package/dist/cjs/createTranslator.cjs +0 -111
- package/dist/cjs/createTranslator.cjs.map +0 -1
- package/dist/cjs/getTranslationsDictionary.cjs +0 -31
- package/dist/cjs/getTranslationsDictionary.cjs.map +0 -1
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs +0 -27
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/hasLocale.cjs +0 -25
- package/dist/cjs/hasLocale.cjs.map +0 -1
- package/dist/cjs/package.cjs +0 -122
- package/dist/cjs/package.cjs.map +0 -1
- package/dist/cjs/useDictionary.cjs +0 -45
- package/dist/cjs/useDictionary.cjs.map +0 -1
- package/dist/cjs/useDictionaryDynamic.cjs +0 -37
- package/dist/cjs/useDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/useTranslationsDictionary.cjs +0 -37
- package/dist/cjs/useTranslationsDictionary.cjs.map +0 -1
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs +0 -29
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs.map +0 -1
- package/dist/esm/_virtual/_rolldown/runtime.mjs +0 -8
- package/dist/esm/client/helpers.mjs +0 -59
- package/dist/esm/client/helpers.mjs.map +0 -1
- package/dist/esm/client/useTranslations.mjs +0 -37
- package/dist/esm/client/useTranslations.mjs.map +0 -1
- package/dist/esm/createFormatter.mjs +0 -57
- package/dist/esm/createFormatter.mjs.map +0 -1
- package/dist/esm/createTranslator.mjs +0 -108
- package/dist/esm/createTranslator.mjs.map +0 -1
- package/dist/esm/getTranslationsDictionary.mjs +0 -29
- package/dist/esm/getTranslationsDictionary.mjs.map +0 -1
- package/dist/esm/getTranslationsDictionaryDynamic.mjs +0 -25
- package/dist/esm/getTranslationsDictionaryDynamic.mjs.map +0 -1
- package/dist/esm/hasLocale.mjs +0 -23
- package/dist/esm/hasLocale.mjs.map +0 -1
- package/dist/esm/package.mjs +0 -119
- package/dist/esm/package.mjs.map +0 -1
- package/dist/esm/useDictionary.mjs +0 -43
- package/dist/esm/useDictionary.mjs.map +0 -1
- package/dist/esm/useDictionaryDynamic.mjs +0 -35
- package/dist/esm/useDictionaryDynamic.mjs.map +0 -1
- package/dist/esm/useTranslationsDictionary.mjs +0 -35
- package/dist/esm/useTranslationsDictionary.mjs.map +0 -1
- package/dist/esm/useTranslationsDictionaryDynamic.mjs +0 -27
- package/dist/esm/useTranslationsDictionaryDynamic.mjs.map +0 -1
- package/dist/types/client/helpers.d.ts +0 -45
- package/dist/types/client/helpers.d.ts.map +0 -1
- package/dist/types/client/useTranslations.d.ts +0 -74
- package/dist/types/client/useTranslations.d.ts.map +0 -1
- package/dist/types/createFormatter.d.ts +0 -15
- package/dist/types/createFormatter.d.ts.map +0 -1
- package/dist/types/createTranslator.d.ts +0 -40
- package/dist/types/createTranslator.d.ts.map +0 -1
- package/dist/types/getTranslationsDictionary.d.ts +0 -15
- package/dist/types/getTranslationsDictionary.d.ts.map +0 -1
- package/dist/types/getTranslationsDictionaryDynamic.d.ts +0 -12
- package/dist/types/getTranslationsDictionaryDynamic.d.ts.map +0 -1
- package/dist/types/hasLocale.d.ts +0 -20
- package/dist/types/hasLocale.d.ts.map +0 -1
- package/dist/types/useDictionary.d.ts +0 -22
- package/dist/types/useDictionary.d.ts.map +0 -1
- package/dist/types/useDictionaryDynamic.d.ts +0 -15
- package/dist/types/useDictionaryDynamic.d.ts.map +0 -1
- package/dist/types/useTranslationsDictionary.d.ts +0 -19
- package/dist/types/useTranslationsDictionary.d.ts.map +0 -1
- package/dist/types/useTranslationsDictionaryDynamic.d.ts +0 -12
- package/dist/types/useTranslationsDictionaryDynamic.d.ts.map +0 -1
|
@@ -4,9 +4,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
6
|
let next_intlayer = require("next-intlayer");
|
|
7
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
7
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
9
8
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
9
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
10
|
+
let next_navigation = require("next/navigation");
|
|
11
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
12
|
|
|
11
13
|
//#region src/client/NextIntlClientProvider.tsx
|
|
12
14
|
/**
|
|
@@ -16,11 +18,14 @@ let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
|
16
18
|
*/
|
|
17
19
|
const NextIntlClientProvider = ({ locale, children, messages: _messages, timeZone: _timeZone, now: _now, ...rest }) => {
|
|
18
20
|
if (process.env.NODE_ENV === "development" && typeof _messages !== "undefined") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("NextIntlClientProvider", _intlayer_config_colors.CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
21
|
+
const pathname = (0, next_navigation.usePathname)();
|
|
22
|
+
const mode = _intlayer_config_built.routing?.mode ?? "prefix-no-default";
|
|
23
|
+
const resolvedLocale = locale ?? (mode === "prefix-all" || mode === "prefix-no-default" ? (0, _intlayer_core_localization.getLocaleFromPath)(pathname) : void 0);
|
|
19
24
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(next_intlayer.IntlayerClientProvider, {
|
|
20
|
-
locale,
|
|
25
|
+
locale: resolvedLocale,
|
|
21
26
|
...rest,
|
|
22
27
|
children
|
|
23
|
-
}, String(
|
|
28
|
+
}, String(resolvedLocale));
|
|
24
29
|
};
|
|
25
30
|
|
|
26
31
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextIntlClientProvider.cjs","names":["CYAN","IntlayerClientProvider"],"sources":["../../../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { NextIntlClientProvider as _NextIntlClientProvider } from 'next-intl';\nimport { IntlayerClientProvider } from 'next-intlayer';\nimport type { ComponentProps } from 'react';\n\n/**\n * Drop-in for next-intl's `NextIntlClientProvider`.\n * `messages`, `timeZone`, and `now` are accepted for API compatibility\n * but have no effect — Intlayer uses its own compiled dictionaries.\n */\nexport const NextIntlClientProvider: typeof _NextIntlClientProvider = ({\n locale,\n children,\n messages: _messages,\n timeZone: _timeZone,\n now: _now,\n ...rest\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('NextIntlClientProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // `key={
|
|
1
|
+
{"version":3,"file":"NextIntlClientProvider.cjs","names":["CYAN","routing","IntlayerClientProvider"],"sources":["../../../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log, routing } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getLocaleFromPath } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { usePathname } from 'next/navigation';\nimport type { NextIntlClientProvider as _NextIntlClientProvider } from 'next-intl';\nimport { IntlayerClientProvider } from 'next-intlayer';\nimport type { ComponentProps } from 'react';\n\n/**\n * Drop-in for next-intl's `NextIntlClientProvider`.\n * `messages`, `timeZone`, and `now` are accepted for API compatibility\n * but have no effect — Intlayer uses its own compiled dictionaries.\n */\nexport const NextIntlClientProvider: typeof _NextIntlClientProvider = ({\n locale,\n children,\n messages: _messages,\n timeZone: _timeZone,\n now: _now,\n ...rest\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('NextIntlClientProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // next-intl drives the locale from the request: apps render\n // `<NextIntlClientProvider>` without a `locale` prop and the server resolves it\n // from the `[locale]` route segment. As a client component we cannot read the\n // server request here, so when no explicit `locale` is given we derive it from\n // the URL (the same `[locale]` segment) using Intlayer's routing config. This\n // keeps `useLocale`, `Link` and the locale switcher in sync with the URL\n // instead of falling back to the stored cookie / default locale.\n //\n // Only prefix-based routing carries the locale in the path. For `no-prefix` /\n // `search-params` the path has no locale segment, so we leave `locale`\n // undefined and let the provider resolve it from storage (cookie) — deriving\n // from the path there would wrongly clobber the cookie with the default locale.\n const pathname = usePathname();\n const mode = routing?.mode ?? 'prefix-no-default';\n const isPrefixMode = mode === 'prefix-all' || mode === 'prefix-no-default';\n const resolvedLocale =\n locale ?? (isPrefixMode ? getLocaleFromPath(pathname) : undefined);\n\n // `key={resolvedLocale}` remounts the provider when the locale changes via\n // navigation (next-intl switches locale by routing to a locale-prefixed path).\n // This re-seeds the client locale context so client components re-render in\n // the new language instead of keeping the previous one.\n return (\n <IntlayerClientProvider\n key={String(resolvedLocale)}\n locale={resolvedLocale}\n {...rest}\n >\n {children}\n </IntlayerClientProvider>\n );\n};\n\n/**\n *\n */\nexport type NextIntlClientProviderProps = Omit<\n ComponentProps<typeof _NextIntlClientProvider>,\n 'messages'\n> & {\n /**\n * @deprecated\n * has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason\n */\n messages?: never;\n /**\n * locale\n */\n locale: LocalesValues;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAa,0BAA0D,EACrE,QACA,UACA,UAAU,WACV,UAAU,WACV,KAAK,MACL,GAAG,WACC;AACJ,KACE,QAAQ,IAAI,aAAa,iBACzB,OAAO,cAAc,YAGrB,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,0BAA0BA,6BAAK,CAAC,+HAC7C;CAeH,MAAM,6CAAwB;CAC9B,MAAM,OAAOC,gCAAS,QAAQ;CAE9B,MAAM,iBACJ,WAFmB,SAAS,gBAAgB,SAAS,yEAET,SAAS,GAAG;AAM1D,QACE,2CAACC,sCAAD;EAEE,QAAQ;EACR,GAAI;EAEH;EACsB,EALlB,OAAO,eAAe,CAKJ"}
|
|
@@ -1,19 +1,62 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const require_useDictionary = require('../useDictionary.cjs');
|
|
4
|
-
const require_client_helpers = require('./helpers.cjs');
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
3
|
const require_client_NextIntlClientProvider = require('./NextIntlClientProvider.cjs');
|
|
6
4
|
const require_client_useLocale = require('./useLocale.cjs');
|
|
7
|
-
|
|
5
|
+
let _intlayer_use_intl = require("@intlayer/use-intl");
|
|
8
6
|
|
|
9
|
-
exports
|
|
7
|
+
Object.defineProperty(exports, 'IntlProvider', {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _intlayer_use_intl.IntlProvider;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
10
13
|
exports.NextIntlClientProvider = require_client_NextIntlClientProvider.NextIntlClientProvider;
|
|
11
|
-
exports
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
Object.defineProperty(exports, 'useDictionary', {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _intlayer_use_intl.useDictionary;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, 'useDictionaryDynamic', {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _intlayer_use_intl.useDictionaryDynamic;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, 'useExtracted', {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return _intlayer_use_intl._useExtracted;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, 'useFormatter', {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _intlayer_use_intl.useFormatter;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
15
38
|
exports.useLocale = require_client_useLocale.useLocale;
|
|
16
|
-
exports
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
39
|
+
Object.defineProperty(exports, 'useMessages', {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return _intlayer_use_intl.useMessages;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, 'useNow', {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () {
|
|
48
|
+
return _intlayer_use_intl.useNow;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, 'useTimeZone', {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _intlayer_use_intl.useTimeZone;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, 'useTranslations', {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () {
|
|
60
|
+
return _intlayer_use_intl.useTranslations;
|
|
61
|
+
}
|
|
62
|
+
});
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,23 +1,100 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_routing = require('./routing.cjs');
|
|
3
|
-
const require_hasLocale = require('./hasLocale.cjs');
|
|
4
|
-
const require_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
5
|
-
const require_useDictionary = require('./useDictionary.cjs');
|
|
6
|
-
const require_client_helpers = require('./client/helpers.cjs');
|
|
7
4
|
const require_client_NextIntlClientProvider = require('./client/NextIntlClientProvider.cjs');
|
|
8
5
|
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
9
|
-
|
|
6
|
+
let _intlayer_use_intl = require("@intlayer/use-intl");
|
|
10
7
|
|
|
11
|
-
exports
|
|
8
|
+
Object.defineProperty(exports, 'IntlError', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _intlayer_use_intl.IntlError;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, 'IntlErrorCode', {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _intlayer_use_intl.IntlErrorCode;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, 'IntlProvider', {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _intlayer_use_intl.IntlProvider;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
12
26
|
exports.NextIntlClientProvider = require_client_NextIntlClientProvider.NextIntlClientProvider;
|
|
27
|
+
Object.defineProperty(exports, 'createFormatter', {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _intlayer_use_intl.createFormatter;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, 'createTranslator', {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _intlayer_use_intl.createTranslator;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
13
39
|
exports.defineRouting = require_routing.defineRouting;
|
|
14
|
-
exports
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
Object.defineProperty(exports, 'hasLocale', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return _intlayer_use_intl.hasLocale;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, 'initializeConfig', {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _intlayer_use_intl.initializeConfig;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, 'useDictionary', {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _intlayer_use_intl.useDictionary;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(exports, 'useDictionaryDynamic', {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return _intlayer_use_intl.useDictionaryDynamic;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, 'useExtracted', {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _intlayer_use_intl._useExtracted;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(exports, 'useFormatter', {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return _intlayer_use_intl.useFormatter;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
19
76
|
exports.useLocale = require_client_useLocale.useLocale;
|
|
20
|
-
exports
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
77
|
+
Object.defineProperty(exports, 'useMessages', {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return _intlayer_use_intl.useMessages;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, 'useNow', {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () {
|
|
86
|
+
return _intlayer_use_intl.useNow;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, 'useTimeZone', {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () {
|
|
92
|
+
return _intlayer_use_intl.useTimeZone;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, 'useTranslations', {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function () {
|
|
98
|
+
return _intlayer_use_intl.useTranslations;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_server_requestLocaleCache = require('./requestLocaleCache.cjs');
|
|
3
4
|
let next_intlayer_server = require("next-intlayer/server");
|
|
4
5
|
|
|
5
6
|
//#region src/server/getLocale.ts
|
|
6
7
|
/**
|
|
7
8
|
* Drop-in for next-intl's `getLocale()` server function.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order mirrors next-intl's per-request model:
|
|
11
|
+
*
|
|
12
|
+
* 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`
|
|
13
|
+
* route segment) — the source of truth for URL-driven routing. This is what
|
|
14
|
+
* keeps server-rendered content and the locale switcher in sync with the URL
|
|
15
|
+
* instead of a stale cookie.
|
|
16
|
+
* 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),
|
|
17
|
+
* for apps that drive the locale from storage rather than the route.
|
|
8
18
|
*/
|
|
9
|
-
const getLocale = async () =>
|
|
19
|
+
const getLocale = async () => {
|
|
20
|
+
const requestLocale = require_server_requestLocaleCache.getCachedRequestLocale();
|
|
21
|
+
if (requestLocale) return requestLocale;
|
|
22
|
+
return await (0, next_intlayer_server.getLocale)();
|
|
23
|
+
};
|
|
10
24
|
|
|
11
25
|
//#endregion
|
|
12
26
|
exports.getLocale = getLocale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.cjs","names":[],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string>
|
|
1
|
+
{"version":3,"file":"getLocale.cjs","names":["getCachedRequestLocale"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\nimport { getCachedRequestLocale } from './requestLocaleCache';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n *\n * Resolution order mirrors next-intl's per-request model:\n *\n * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`\n * route segment) — the source of truth for URL-driven routing. This is what\n * keeps server-rendered content and the locale switcher in sync with the URL\n * instead of a stale cookie.\n * 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),\n * for apps that drive the locale from storage rather than the route.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string> => {\n const requestLocale = getCachedRequestLocale();\n if (requestLocale) return requestLocale as string;\n\n return (await getLocaleIntlayer()) as string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAa,YAA+B,YAA6B;CACvE,MAAM,gBAAgBA,0DAAwB;AAC9C,KAAI,cAAe,QAAO;AAE1B,QAAQ,2CAAyB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
5
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
|
+
|
|
7
|
+
//#region src/server/getRequestConfig.ts
|
|
8
|
+
/**
|
|
9
|
+
* Drop-in for next-intl's `getRequestConfig`.
|
|
10
|
+
*
|
|
11
|
+
* In next-intl this registers the per-request config (locale + messages) read
|
|
12
|
+
* by its own plugin. With intlayer the locale is resolved from routing /
|
|
13
|
+
* storage and messages come from compiled dictionaries, so the returned config
|
|
14
|
+
* is never consumed — this is an identity passthrough kept so existing
|
|
15
|
+
* `i18n/request.ts` files keep resolving and type-checking.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated getRequestConfig has no use case with intlayer. The locale and
|
|
18
|
+
* messages are resolved automatically; the file can be removed.
|
|
19
|
+
*/
|
|
20
|
+
const getRequestConfig = (createRequestConfig) => {
|
|
21
|
+
if (process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("getRequestConfig", _intlayer_config_colors.CYAN)} has no use case with intlayer. The locale and messages are resolved automatically; the i18n/request.ts file can be removed`);
|
|
22
|
+
return createRequestConfig;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.default = getRequestConfig;
|
|
27
|
+
exports.getRequestConfig = getRequestConfig;
|
|
28
|
+
//# sourceMappingURL=getRequestConfig.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRequestConfig.cjs","names":["CYAN"],"sources":["../../../src/server/getRequestConfig.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getRequestConfig as _getRequestConfig } from 'next-intl/server';\n\n/**\n * Drop-in for next-intl's `getRequestConfig`.\n *\n * In next-intl this registers the per-request config (locale + messages) read\n * by its own plugin. With intlayer the locale is resolved from routing /\n * storage and messages come from compiled dictionaries, so the returned config\n * is never consumed — this is an identity passthrough kept so existing\n * `i18n/request.ts` files keep resolving and type-checking.\n *\n * @deprecated getRequestConfig has no use case with intlayer. The locale and\n * messages are resolved automatically; the file can be removed.\n */\nexport const getRequestConfig: typeof _getRequestConfig = (\n createRequestConfig\n) => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getRequestConfig', CYAN)} has no use case with intlayer. The locale and messages are resolved automatically; the i18n/request.ts file can be removed`\n );\n }\n\n return createRequestConfig;\n};\n\nexport default getRequestConfig;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,MAAa,oBACX,wBACG;AACH,KAAI,QAAQ,IAAI,aAAa,cAE3B,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,oBAAoBA,6BAAK,CAAC,6HACvC;AAGH,QAAO"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_server_getLocale = require('./getLocale.cjs');
|
|
3
|
-
|
|
4
|
+
let _intlayer_use_intl = require("@intlayer/use-intl");
|
|
4
5
|
|
|
5
6
|
//#region src/server/getTranslations.ts
|
|
6
7
|
/**
|
|
@@ -11,8 +12,9 @@ const require_createTranslator = require('../createTranslator.cjs');
|
|
|
11
12
|
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
12
13
|
* and `t.markup()`.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* Resolves the active locale from the current request (or the `locale` option)
|
|
16
|
+
* and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime
|
|
17
|
+
* that backs the client `useTranslations`.
|
|
16
18
|
*
|
|
17
19
|
* @example
|
|
18
20
|
* ```ts
|
|
@@ -37,7 +39,10 @@ const getTranslations = (async (namespaceOrOptions) => {
|
|
|
37
39
|
namespace = namespaceOrOptions.namespace;
|
|
38
40
|
localeOverride = namespaceOrOptions.locale;
|
|
39
41
|
} else namespace = namespaceOrOptions;
|
|
40
|
-
return
|
|
42
|
+
return (0, _intlayer_use_intl.createTranslator)({
|
|
43
|
+
locale: localeOverride ?? await require_server_getLocale.getLocale(),
|
|
44
|
+
namespace
|
|
45
|
+
});
|
|
41
46
|
});
|
|
42
47
|
|
|
43
48
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslations.cjs","names":["
|
|
1
|
+
{"version":3,"file":"getTranslations.cjs","names":["getLocale"],"sources":["../../../src/server/getTranslations.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n createTranslator,\n type LooseTranslateFunction,\n type TranslateFunction,\n} from '@intlayer/use-intl';\nimport { getLocale } from './getLocale';\n\n/**\n * Options accepted by the options-object overload of {@link getTranslations}.\n */\ntype GetTranslationsOptions<N extends DictionaryKeys> = {\n /** The dictionary namespace to scope translations to. */\n namespace?: N;\n /** Override the locale instead of reading it from the current request. */\n locale?: LocalesValues;\n};\n\n/**\n * Overload set for {@link getTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. An options object `{ namespace?, locale? }` → typed when namespace is\n * a known `DictionaryKeys` value.\n * 3. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching next-intl's scoped-namespace behaviour.\n * 4. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n *\n * The translate function shape (`t`, `t.rich`, `t.markup`, `t.raw`, `t.has`)\n * is shared with `@intlayer/use-intl`.\n */\ntype GetTranslations = {\n <N extends DictionaryKeys>(namespace: N): Promise<TranslateFunction<N>>;\n <N extends DictionaryKeys>(\n options: GetTranslationsOptions<N>\n ): Promise<TranslateFunction<N>>;\n (namespace: `${string}.${string}`): Promise<LooseTranslateFunction>;\n (): Promise<LooseTranslateFunction>;\n};\n\n/**\n * Drop-in for next-intl's server `getTranslations()`.\n *\n * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),\n * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted\n * arguments (`{value, number}`). Rich text is available through `t.rich()`\n * and `t.markup()`.\n *\n * Resolves the active locale from the current request (or the `locale` option)\n * and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime\n * that backs the client `useTranslations`.\n *\n * @example\n * ```ts\n * // Bare namespace — fully typed dot-paths\n * const t = await getTranslations('about');\n * return <h1>{t('counter.label')}</h1>;\n *\n * // ICU plural\n * t('items', { count: 3 });\n *\n * // Options object with locale override\n * const t = await getTranslations({ namespace: 'about', locale: 'fr' });\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const getTranslations: GetTranslations = (async (\n namespaceOrOptions?: string | GetTranslationsOptions<DictionaryKeys>\n) => {\n let namespace: string | undefined;\n let localeOverride: LocalesValues | undefined;\n\n if (typeof namespaceOrOptions === 'object' && namespaceOrOptions !== null) {\n namespace = namespaceOrOptions.namespace;\n localeOverride = namespaceOrOptions.locale;\n } else {\n namespace = namespaceOrOptions as string | undefined;\n }\n\n const locale = localeOverride ?? (await getLocale());\n\n return createTranslator({ locale: locale as LocalesValues, namespace });\n}) as GetTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAa,mBAAoC,OAC/C,uBACG;CACH,IAAI;CACJ,IAAI;AAEJ,KAAI,OAAO,uBAAuB,YAAY,uBAAuB,MAAM;AACzE,cAAY,mBAAmB;AAC/B,mBAAiB,mBAAmB;OAEpC,aAAY;AAKd,iDAAwB;EAAE,QAFX,kBAAmB,MAAMA,oCAAW;EAEQ;EAAW,CAAC"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_server_getLocale = require('./getLocale.cjs');
|
|
4
|
+
let _intlayer_use_intl = require("@intlayer/use-intl");
|
|
4
5
|
|
|
5
6
|
//#region src/server/helpers.ts
|
|
6
7
|
/**
|
|
7
8
|
* Drop-in for next-intl's server `getFormatter()`.
|
|
8
|
-
* Returns locale-aware formatters backed by the native `Intl.*` APIs
|
|
9
|
+
* Returns locale-aware formatters backed by the native `Intl.*` APIs,
|
|
10
|
+
* built by `@intlayer/use-intl`'s `createFormatter`.
|
|
9
11
|
*/
|
|
10
12
|
const getFormatter = (async (options) => {
|
|
11
|
-
return
|
|
13
|
+
return (0, _intlayer_use_intl.createFormatter)({ locale: options?.locale ?? await require_server_getLocale.getLocale() });
|
|
12
14
|
});
|
|
13
15
|
/**
|
|
14
16
|
* Drop-in for next-intl's server `getNow()`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","names":["
|
|
1
|
+
{"version":3,"file":"helpers.cjs","names":["getLocale"],"sources":["../../../src/server/helpers.ts"],"sourcesContent":["import { createFormatter } from '@intlayer/use-intl';\nimport type {\n getFormatter as _getFormatter,\n getNow as _getNow,\n getTimeZone as _getTimeZone,\n} from 'next-intl/server';\nimport { getLocale } from './getLocale';\n\n/**\n * Drop-in for next-intl's server `getFormatter()`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs,\n * built by `@intlayer/use-intl`'s `createFormatter`.\n */\nexport const getFormatter: typeof _getFormatter = (async (options?: {\n locale?: string;\n}) => {\n const locale = options?.locale ?? (await getLocale());\n return createFormatter({ locale: locale as string });\n}) as typeof _getFormatter;\n\n/**\n * Drop-in for next-intl's server `getNow()`.\n * Returns the current `Date`.\n */\nexport const getNow: typeof _getNow = (async () =>\n new Date()) as typeof _getNow;\n\n/**\n * Drop-in for next-intl's server `getTimeZone()`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const getTimeZone: typeof _getTimeZone = (async () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone) as typeof _getTimeZone;\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,gBAAsC,OAAO,YAEpD;AAEJ,gDAAuB,EAAE,QADV,SAAS,UAAW,MAAMA,oCAAW,EACD,CAAC;;;;;;AAOtD,MAAa,UAA0B,4BACrC,IAAI,MAAM;;;;;AAMZ,MAAa,eAAoC,YAC/C,KAAK,gBAAgB,CAAC,iBAAiB,CAAC"}
|
|
@@ -3,6 +3,8 @@ const require_server_getLocale = require('./getLocale.cjs');
|
|
|
3
3
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
4
4
|
const require_getDictionaryDynamic = require('../getDictionaryDynamic.cjs');
|
|
5
5
|
const require_server_helpers = require('./helpers.cjs');
|
|
6
|
+
const require_server_getRequestConfig = require('./getRequestConfig.cjs');
|
|
7
|
+
const require_server_setRequestLocale = require('./setRequestLocale.cjs');
|
|
6
8
|
const require_server_setLocale = require('./setLocale.cjs');
|
|
7
9
|
const require_server_getTranslations = require('./getTranslations.cjs');
|
|
8
10
|
const require_server_getMessages = require('./getMessages.cjs');
|
|
@@ -13,6 +15,8 @@ exports.getFormatter = require_server_helpers.getFormatter;
|
|
|
13
15
|
exports.getLocale = require_server_getLocale.getLocale;
|
|
14
16
|
exports.getMessages = require_server_getMessages.getMessages;
|
|
15
17
|
exports.getNow = require_server_helpers.getNow;
|
|
18
|
+
exports.getRequestConfig = require_server_getRequestConfig;
|
|
16
19
|
exports.getTimeZone = require_server_helpers.getTimeZone;
|
|
17
20
|
exports.getTranslations = require_server_getTranslations.getTranslations;
|
|
18
|
-
exports.setLocale = require_server_setLocale.setLocale;
|
|
21
|
+
exports.setLocale = require_server_setLocale.setLocale;
|
|
22
|
+
exports.setRequestLocale = require_server_setRequestLocale.setRequestLocale;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
|
|
5
|
+
//#region src/server/requestLocaleCache.ts
|
|
6
|
+
/**
|
|
7
|
+
* Request-scoped holder for the locale provided through {@link setRequestLocale}.
|
|
8
|
+
*
|
|
9
|
+
* next-intl resolves the active locale per request from the `[locale]` route
|
|
10
|
+
* segment, which the app forwards via `setRequestLocale(locale)`. React's
|
|
11
|
+
* `cache()` gives a per-request singleton (the same trick next-intl uses in its
|
|
12
|
+
* own `RequestLocaleCache`), so the value set in the layout/page is readable by
|
|
13
|
+
* the other server APIs (`getLocale`, `getTranslations`, …) during the same
|
|
14
|
+
* render.
|
|
15
|
+
*
|
|
16
|
+
* @see https://github.com/vercel/next.js/discussions/58862
|
|
17
|
+
*/
|
|
18
|
+
const getRequestLocaleHolder = (0, react.cache)(() => ({ locale: void 0 }));
|
|
19
|
+
/**
|
|
20
|
+
* Read the locale stored for the current request, or `undefined` when
|
|
21
|
+
* `setRequestLocale` has not been called.
|
|
22
|
+
*/
|
|
23
|
+
const getCachedRequestLocale = () => getRequestLocaleHolder().locale;
|
|
24
|
+
/**
|
|
25
|
+
* Store the locale for the current request. Called by `setRequestLocale`.
|
|
26
|
+
*
|
|
27
|
+
* @param locale - The locale resolved from the `[locale]` route segment.
|
|
28
|
+
*/
|
|
29
|
+
const setCachedRequestLocale = (locale) => {
|
|
30
|
+
getRequestLocaleHolder().locale = locale;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.getCachedRequestLocale = getCachedRequestLocale;
|
|
35
|
+
exports.setCachedRequestLocale = setCachedRequestLocale;
|
|
36
|
+
//# sourceMappingURL=requestLocaleCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestLocaleCache.cjs","names":[],"sources":["../../../src/server/requestLocaleCache.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cache } from 'react';\n\n/**\n * Request-scoped holder for the locale provided through {@link setRequestLocale}.\n *\n * next-intl resolves the active locale per request from the `[locale]` route\n * segment, which the app forwards via `setRequestLocale(locale)`. React's\n * `cache()` gives a per-request singleton (the same trick next-intl uses in its\n * own `RequestLocaleCache`), so the value set in the layout/page is readable by\n * the other server APIs (`getLocale`, `getTranslations`, …) during the same\n * render.\n *\n * @see https://github.com/vercel/next.js/discussions/58862\n */\nconst getRequestLocaleHolder = cache((): { locale?: LocalesValues } => ({\n locale: undefined,\n}));\n\n/**\n * Read the locale stored for the current request, or `undefined` when\n * `setRequestLocale` has not been called.\n */\nexport const getCachedRequestLocale = (): LocalesValues | undefined =>\n getRequestLocaleHolder().locale;\n\n/**\n * Store the locale for the current request. Called by `setRequestLocale`.\n *\n * @param locale - The locale resolved from the `[locale]` route segment.\n */\nexport const setCachedRequestLocale = (locale: LocalesValues): void => {\n getRequestLocaleHolder().locale = locale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,MAAM,iDAAkE,EACtE,QAAQ,QACT,EAAE;;;;;AAMH,MAAa,+BACX,wBAAwB,CAAC;;;;;;AAO3B,MAAa,0BAA0B,WAAgC;AACrE,yBAAwB,CAAC,SAAS"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_server_requestLocaleCache = require('./requestLocaleCache.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/server/setRequestLocale.ts
|
|
5
|
+
/**
|
|
6
|
+
* Drop-in for next-intl's `setRequestLocale`.
|
|
7
|
+
*
|
|
8
|
+
* In next-intl this stores the locale (typically the `[locale]` route segment)
|
|
9
|
+
* in a request-scoped cache so the rest of the request can render in that
|
|
10
|
+
* locale and opt into static rendering. The compat keeps the same contract:
|
|
11
|
+
* the locale is stored per-request and read back by `getLocale()` (and, through
|
|
12
|
+
* it, `getTranslations` / `getDictionary` / metadata). This is what makes the
|
|
13
|
+
* per-request locale — and therefore the locale switcher — work without relying
|
|
14
|
+
* on a cookie.
|
|
15
|
+
*
|
|
16
|
+
* @param locale - The locale resolved from the `[locale]` route segment.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* export default async function LocaleLayout({ params }) {
|
|
21
|
+
* const { locale } = await params;
|
|
22
|
+
* setRequestLocale(locale);
|
|
23
|
+
* // …
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const setRequestLocale = (locale) => {
|
|
28
|
+
require_server_requestLocaleCache.setCachedRequestLocale(locale);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.setRequestLocale = setRequestLocale;
|
|
33
|
+
//# sourceMappingURL=setRequestLocale.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setRequestLocale.cjs","names":[],"sources":["../../../src/server/setRequestLocale.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { setRequestLocale as _setRequestLocale } from 'next-intl/server';\nimport { setCachedRequestLocale } from './requestLocaleCache';\n\n/**\n * Drop-in for next-intl's `setRequestLocale`.\n *\n * In next-intl this stores the locale (typically the `[locale]` route segment)\n * in a request-scoped cache so the rest of the request can render in that\n * locale and opt into static rendering. The compat keeps the same contract:\n * the locale is stored per-request and read back by `getLocale()` (and, through\n * it, `getTranslations` / `getDictionary` / metadata). This is what makes the\n * per-request locale — and therefore the locale switcher — work without relying\n * on a cookie.\n *\n * @param locale - The locale resolved from the `[locale]` route segment.\n *\n * @example\n * ```ts\n * export default async function LocaleLayout({ params }) {\n * const { locale } = await params;\n * setRequestLocale(locale);\n * // …\n * }\n * ```\n */\nexport const setRequestLocale: typeof _setRequestLocale = (locale): void => {\n setCachedRequestLocale(locale as LocalesValues);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,oBAA8C,WAAiB;AAC1E,0DAAuB,OAAwB"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { log } from "@intlayer/config/built";
|
|
3
|
+
import { log, routing } from "@intlayer/config/built";
|
|
4
4
|
import { IntlayerClientProvider } from "next-intlayer";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
6
5
|
import { CYAN } from "@intlayer/config/colors";
|
|
7
6
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
7
|
+
import { getLocaleFromPath } from "@intlayer/core/localization";
|
|
8
|
+
import { usePathname } from "next/navigation";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
10
|
|
|
9
11
|
//#region src/client/NextIntlClientProvider.tsx
|
|
10
12
|
/**
|
|
@@ -14,11 +16,14 @@ import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
|
14
16
|
*/
|
|
15
17
|
const NextIntlClientProvider = ({ locale, children, messages: _messages, timeZone: _timeZone, now: _now, ...rest }) => {
|
|
16
18
|
if (typeof _messages !== "undefined") getAppLogger({ log })(`${colorize("NextIntlClientProvider", CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
19
|
+
const pathname = usePathname();
|
|
20
|
+
const mode = routing?.mode ?? "prefix-no-default";
|
|
21
|
+
const resolvedLocale = locale ?? (mode === "prefix-all" || mode === "prefix-no-default" ? getLocaleFromPath(pathname) : void 0);
|
|
17
22
|
return /* @__PURE__ */ jsx(IntlayerClientProvider, {
|
|
18
|
-
locale,
|
|
23
|
+
locale: resolvedLocale,
|
|
19
24
|
...rest,
|
|
20
25
|
children
|
|
21
|
-
}, String(
|
|
26
|
+
}, String(resolvedLocale));
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextIntlClientProvider.mjs","names":[],"sources":["../../../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { NextIntlClientProvider as _NextIntlClientProvider } from 'next-intl';\nimport { IntlayerClientProvider } from 'next-intlayer';\nimport type { ComponentProps } from 'react';\n\n/**\n * Drop-in for next-intl's `NextIntlClientProvider`.\n * `messages`, `timeZone`, and `now` are accepted for API compatibility\n * but have no effect — Intlayer uses its own compiled dictionaries.\n */\nexport const NextIntlClientProvider: typeof _NextIntlClientProvider = ({\n locale,\n children,\n messages: _messages,\n timeZone: _timeZone,\n now: _now,\n ...rest\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('NextIntlClientProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // `key={
|
|
1
|
+
{"version":3,"file":"NextIntlClientProvider.mjs","names":[],"sources":["../../../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log, routing } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getLocaleFromPath } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { usePathname } from 'next/navigation';\nimport type { NextIntlClientProvider as _NextIntlClientProvider } from 'next-intl';\nimport { IntlayerClientProvider } from 'next-intlayer';\nimport type { ComponentProps } from 'react';\n\n/**\n * Drop-in for next-intl's `NextIntlClientProvider`.\n * `messages`, `timeZone`, and `now` are accepted for API compatibility\n * but have no effect — Intlayer uses its own compiled dictionaries.\n */\nexport const NextIntlClientProvider: typeof _NextIntlClientProvider = ({\n locale,\n children,\n messages: _messages,\n timeZone: _timeZone,\n now: _now,\n ...rest\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('NextIntlClientProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // next-intl drives the locale from the request: apps render\n // `<NextIntlClientProvider>` without a `locale` prop and the server resolves it\n // from the `[locale]` route segment. As a client component we cannot read the\n // server request here, so when no explicit `locale` is given we derive it from\n // the URL (the same `[locale]` segment) using Intlayer's routing config. This\n // keeps `useLocale`, `Link` and the locale switcher in sync with the URL\n // instead of falling back to the stored cookie / default locale.\n //\n // Only prefix-based routing carries the locale in the path. For `no-prefix` /\n // `search-params` the path has no locale segment, so we leave `locale`\n // undefined and let the provider resolve it from storage (cookie) — deriving\n // from the path there would wrongly clobber the cookie with the default locale.\n const pathname = usePathname();\n const mode = routing?.mode ?? 'prefix-no-default';\n const isPrefixMode = mode === 'prefix-all' || mode === 'prefix-no-default';\n const resolvedLocale =\n locale ?? (isPrefixMode ? getLocaleFromPath(pathname) : undefined);\n\n // `key={resolvedLocale}` remounts the provider when the locale changes via\n // navigation (next-intl switches locale by routing to a locale-prefixed path).\n // This re-seeds the client locale context so client components re-render in\n // the new language instead of keeping the previous one.\n return (\n <IntlayerClientProvider\n key={String(resolvedLocale)}\n locale={resolvedLocale}\n {...rest}\n >\n {children}\n </IntlayerClientProvider>\n );\n};\n\n/**\n *\n */\nexport type NextIntlClientProviderProps = Omit<\n ComponentProps<typeof _NextIntlClientProvider>,\n 'messages'\n> & {\n /**\n * @deprecated\n * has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason\n */\n messages?: never;\n /**\n * locale\n */\n locale: LocalesValues;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAa,0BAA0D,EACrE,QACA,UACA,UAAU,WACV,UAAU,WACV,KAAK,MACL,GAAG,WACC;AACJ,KAEE,OAAO,cAAc,YAGrB,CADkB,aAAa,EAAE,KAAK,CAC7B,CACP,GAAG,SAAS,0BAA0B,KAAK,CAAC,+HAC7C;CAeH,MAAM,WAAW,aAAa;CAC9B,MAAM,OAAO,SAAS,QAAQ;CAE9B,MAAM,iBACJ,WAFmB,SAAS,gBAAgB,SAAS,sBAE3B,kBAAkB,SAAS,GAAG;AAM1D,QACE,oBAAC,wBAAD;EAEE,QAAQ;EACR,GAAI;EAEH;EACsB,EALlB,OAAO,eAAe,CAKJ"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { useDictionaryDynamic } from "../useDictionaryDynamic.mjs";
|
|
2
|
-
import { useDictionary } from "../useDictionary.mjs";
|
|
3
|
-
import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./helpers.mjs";
|
|
4
1
|
import { NextIntlClientProvider } from "./NextIntlClientProvider.mjs";
|
|
5
2
|
import { useLocale } from "./useLocale.mjs";
|
|
6
|
-
import { useTranslations } from "
|
|
3
|
+
import { IntlProvider, _useExtracted as useExtracted, useDictionary, useDictionaryDynamic, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "@intlayer/use-intl";
|
|
7
4
|
|
|
8
5
|
export { IntlProvider, NextIntlClientProvider, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { defineRouting } from "./routing.mjs";
|
|
2
|
-
import { hasLocale } from "./hasLocale.mjs";
|
|
3
|
-
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
4
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
5
|
-
import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.mjs";
|
|
6
2
|
import { NextIntlClientProvider } from "./client/NextIntlClientProvider.mjs";
|
|
7
3
|
import { useLocale } from "./client/useLocale.mjs";
|
|
8
|
-
import { useTranslations } from "./client/
|
|
4
|
+
import { IntlProvider, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "./client/index.mjs";
|
|
5
|
+
import { IntlError, IntlErrorCode, createFormatter, createTranslator, hasLocale, initializeConfig } from "@intlayer/use-intl";
|
|
9
6
|
|
|
10
|
-
export { IntlProvider, NextIntlClientProvider, defineRouting, hasLocale, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
7
|
+
export { IntlError, IntlErrorCode, IntlProvider, NextIntlClientProvider, createFormatter, createTranslator, defineRouting, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import { getCachedRequestLocale } from "./requestLocaleCache.mjs";
|
|
1
2
|
import { getLocale as getLocale$1 } from "next-intlayer/server";
|
|
2
3
|
|
|
3
4
|
//#region src/server/getLocale.ts
|
|
4
5
|
/**
|
|
5
6
|
* Drop-in for next-intl's `getLocale()` server function.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order mirrors next-intl's per-request model:
|
|
9
|
+
*
|
|
10
|
+
* 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`
|
|
11
|
+
* route segment) — the source of truth for URL-driven routing. This is what
|
|
12
|
+
* keeps server-rendered content and the locale switcher in sync with the URL
|
|
13
|
+
* instead of a stale cookie.
|
|
14
|
+
* 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),
|
|
15
|
+
* for apps that drive the locale from storage rather than the route.
|
|
6
16
|
*/
|
|
7
|
-
const getLocale = async () =>
|
|
17
|
+
const getLocale = async () => {
|
|
18
|
+
const requestLocale = getCachedRequestLocale();
|
|
19
|
+
if (requestLocale) return requestLocale;
|
|
20
|
+
return await getLocale$1();
|
|
21
|
+
};
|
|
8
22
|
|
|
9
23
|
//#endregion
|
|
10
24
|
export { getLocale };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.mjs","names":["getLocaleIntlayer"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string>
|
|
1
|
+
{"version":3,"file":"getLocale.mjs","names":["getLocaleIntlayer"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\nimport { getCachedRequestLocale } from './requestLocaleCache';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n *\n * Resolution order mirrors next-intl's per-request model:\n *\n * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`\n * route segment) — the source of truth for URL-driven routing. This is what\n * keeps server-rendered content and the locale switcher in sync with the URL\n * instead of a stale cookie.\n * 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),\n * for apps that drive the locale from storage rather than the route.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string> => {\n const requestLocale = getCachedRequestLocale();\n if (requestLocale) return requestLocale as string;\n\n return (await getLocaleIntlayer()) as string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAa,YAA+B,YAA6B;CACvE,MAAM,gBAAgB,wBAAwB;AAC9C,KAAI,cAAe,QAAO;AAE1B,QAAQ,MAAMA,aAAmB"}
|