@intlayer/next-i18next 9.0.0-canary.8 → 9.0.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.
- package/dist/cjs/appWithTranslation.cjs +0 -1
- package/dist/cjs/appWithTranslation.cjs.map +1 -1
- package/dist/cjs/index.cjs +0 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/plugin/index.cjs +9 -13
- package/dist/cjs/plugin/index.cjs.map +1 -1
- package/dist/cjs/serverSideTranslations.cjs +0 -1
- package/dist/cjs/serverSideTranslations.cjs.map +1 -1
- package/dist/esm/appWithTranslation.mjs.map +1 -1
- package/dist/esm/plugin/index.mjs +8 -12
- package/dist/esm/plugin/index.mjs.map +1 -1
- package/dist/esm/serverSideTranslations.mjs.map +1 -1
- package/dist/types/appWithTranslation.d.ts +0 -1
- package/dist/types/appWithTranslation.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/plugin/index.d.ts +0 -1
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/serverSideTranslations.d.ts.map +1 -1
- package/package.json +16 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appWithTranslation.cjs","names":["IntlayerProvider"],"sources":["../../src/appWithTranslation.tsx"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { appWithTranslation as _appWithTranslation } from 'next-i18next/pages';\nimport type * as React from 'react';\nimport { IntlayerProvider } from 'react-intlayer';\n\n/**\n * Drop-in replacement for next-i18next's `appWithTranslation` HOC.\n *\n * Wraps the Next.js `App` component in `IntlayerProvider` and passes the\n * active locale from `_nextI18Next.initialLocale` or the Next.js router.\n *\n * @example\n * ```tsx\n * export default appWithTranslation(MyApp);\n * ```\n */\nexport const appWithTranslation: typeof _appWithTranslation = (\n WrappedApp,\n _configOverride?\n) => {\n const AppWithTranslation = (\n props: React.ComponentProps<typeof WrappedApp> & {\n pageProps: {\n _nextI18Next?: { initialLocale?: string };\n [key: string]: unknown;\n };\n router?: { locale?: string };\n }\n ) => {\n const locale: string | undefined =\n props.pageProps?._nextI18Next?.initialLocale ?? props.router?.locale;\n\n return (\n <IntlayerProvider locale={locale as LocalesValues}>\n <WrappedApp {...props} />\n </IntlayerProvider>\n );\n };\n\n AppWithTranslation.displayName = `appWithTranslation(${\n WrappedApp.displayName ?? WrappedApp.name ?? 'App'\n })`;\n\n return AppWithTranslation as unknown as ReturnType<\n typeof _appWithTranslation\n >;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"appWithTranslation.cjs","names":["IntlayerProvider"],"sources":["../../src/appWithTranslation.tsx"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { appWithTranslation as _appWithTranslation } from 'next-i18next/pages';\nimport type * as React from 'react';\nimport { IntlayerProvider } from 'react-intlayer';\n\n/**\n * Drop-in replacement for next-i18next's `appWithTranslation` HOC.\n *\n * Wraps the Next.js `App` component in `IntlayerProvider` and passes the\n * active locale from `_nextI18Next.initialLocale` or the Next.js router.\n *\n * @example\n * ```tsx\n * export default appWithTranslation(MyApp);\n * ```\n */\nexport const appWithTranslation: typeof _appWithTranslation = (\n WrappedApp,\n _configOverride?\n) => {\n const AppWithTranslation = (\n props: React.ComponentProps<typeof WrappedApp> & {\n pageProps: {\n _nextI18Next?: { initialLocale?: string };\n [key: string]: unknown;\n };\n router?: { locale?: string };\n }\n ) => {\n const locale: string | undefined =\n props.pageProps?._nextI18Next?.initialLocale ?? props.router?.locale;\n\n return (\n <IntlayerProvider locale={locale as LocalesValues}>\n <WrappedApp {...props} />\n </IntlayerProvider>\n );\n };\n\n AppWithTranslation.displayName = `appWithTranslation(${\n WrappedApp.displayName ?? WrappedApp.name ?? 'App'\n })`;\n\n return AppWithTranslation as unknown as ReturnType<\n typeof _appWithTranslation\n >;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAa,sBACX,YACA,oBACG;CACH,MAAM,sBACJ,UAOG;EAIH,OACE,2CAACA,iCAAD;GAAkB,QAHlB,MAAM,WAAW,cAAc,iBAAiB,MAAM,QAAQ;aAI5D,2CAAC,YAAD,EAAY,GAAI,MAAQ;EACR;CAEtB;CAEA,mBAAmB,cAAc,sBAC/B,WAAW,eAAe,WAAW,QAAQ,MAC9C;CAED,OAAO;AAGT"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_appWithTranslation = require('./appWithTranslation.cjs');
|
|
4
3
|
const require_serverSideTranslations = require('./serverSideTranslations.cjs');
|
|
5
4
|
let _intlayer_i18next = require("@intlayer/i18next");
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["i18next"],"sources":["../../src/index.ts"],"sourcesContent":["import { type i18n as I18nType, i18next } from '@intlayer/i18next';\n\nexport const i18n = i18next as unknown as I18nType;\n\nexport {\n I18nContext,\n I18nextProvider,\n initReactI18next,\n Trans,\n Translation,\n useDictionary,\n useDictionaryDynamic,\n useTranslation,\n withTranslation,\n} from '@intlayer/react-i18next';\n\nexport { appWithTranslation } from './appWithTranslation';\nexport { serverSideTranslations } from './serverSideTranslations';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["i18next"],"sources":["../../src/index.ts"],"sourcesContent":["import { type i18n as I18nType, i18next } from '@intlayer/i18next';\n\nexport const i18n = i18next as unknown as I18nType;\n\nexport {\n I18nContext,\n I18nextProvider,\n initReactI18next,\n Trans,\n Translation,\n useDictionary,\n useDictionaryDynamic,\n useTranslation,\n withTranslation,\n} from '@intlayer/react-i18next';\n\nexport { appWithTranslation } from './appWithTranslation';\nexport { serverSideTranslations } from './serverSideTranslations';\n"],"mappings":";;;;;;;AAEA,MAAa,OAAOA"}
|
|
@@ -5,8 +5,9 @@ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
|
5
5
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
6
|
let node_module = require("node:module");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
|
-
let
|
|
8
|
+
let _intlayer_config_callers = require("@intlayer/config/callers");
|
|
9
9
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
10
|
+
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
10
11
|
let next_intlayer_server = require("next-intlayer/server");
|
|
11
12
|
|
|
12
13
|
//#region src/plugin/index.ts
|
|
@@ -81,17 +82,12 @@ const resolveEsmPath = (specifier) => {
|
|
|
81
82
|
* @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.
|
|
82
83
|
*/
|
|
83
84
|
const toTurbopackAlias = (absolutePath) => `./${(0, node_path.relative)(process.cwd(), absolutePath).split(node_path.sep).join("/")}`;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
],
|
|
91
|
-
namespaceArgIndex: 0,
|
|
92
|
-
staticReplacement: "useDictionary",
|
|
93
|
-
dynamicReplacement: "useDictionaryDynamic"
|
|
94
|
-
}];
|
|
85
|
+
/**
|
|
86
|
+
* SWC extra-caller configs derived from the shared caller registry
|
|
87
|
+
* (`@intlayer/config/callers`) — the single source of truth also consumed by
|
|
88
|
+
* the babel analyzer/optimizer and the LSP.
|
|
89
|
+
*/
|
|
90
|
+
const NEXT_I18NEXT_SWC_CALLERS = (0, _intlayer_config_callers.toSwcExtraCallers)(_intlayer_config_callers.REACT_I18NEXT_CALLERS);
|
|
95
91
|
/**
|
|
96
92
|
* Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js
|
|
97
93
|
* config so the runtime dictionary registry stays populated. Mutates the
|
|
@@ -118,7 +114,7 @@ const createNextI18nPlugin = (_i18nPath) => {
|
|
|
118
114
|
return async (nextConfig = {}) => {
|
|
119
115
|
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
120
116
|
const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
|
|
121
|
-
(0,
|
|
117
|
+
(0, _intlayer_engine_utils.runOnce)((0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", "intlayer-issues-invitation.lock"), () => {
|
|
122
118
|
appLogger([(0, _intlayer_config_logger.colorize)("Please report any issues you met on GitHub:", _intlayer_config_colors.GREY), (0, _intlayer_config_logger.colorize)("https://github.com/aymericzip/intlayer/issues", _intlayer_config_colors.GREY_LIGHT)]);
|
|
123
119
|
}, { cacheTimeoutMs: 1e3 * 60 * 60 });
|
|
124
120
|
const customWebpack = nextConfig.webpack;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["sep","ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\nconst NEXT_I18NEXT_SWC_CALLERS = [\n {\n callerName: 'useTranslation',\n importSources: ['react-i18next', '@intlayer/react-i18next', 'next-i18next'],\n namespaceArgIndex: 0,\n staticReplacement: 'useDictionary',\n dynamicReplacement: 'useDictionaryDynamic',\n },\n];\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\n * export default withI18next(nextConfig);\n * ```\n */\nexport const withI18next = createNextI18nPlugin();\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAM,6FAA8C;;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
|
1
|
+
{"version":3,"file":"index.cjs","names":["sep","REACT_I18NEXT_CALLERS","ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport {\n REACT_I18NEXT_CALLERS,\n toSwcExtraCallers,\n} from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\n/**\n * SWC extra-caller configs derived from the shared caller registry\n * (`@intlayer/config/callers`) — the single source of truth also consumed by\n * the babel analyzer/optimizer and the LSP.\n */\nconst NEXT_I18NEXT_SWC_CALLERS = toSwcExtraCallers(REACT_I18NEXT_CALLERS);\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\n * export default withI18next(nextConfig);\n * ```\n */\nexport const withI18next = createNextI18nPlugin();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,4FAA6C;;;;;AAMnD,MAAM,gBAA4D;CAChE;EAAE,SAAS;EAAgB,aAAa;CAAyB;CACjE;EAAE,SAAS;EAAiB,aAAa;CAA0B;CACnE;EAAE,SAAS;EAAW,aAAa;CAAoB;AACzD;;;;;;;;AASA,MAAM,kBACJ,cAC+C;CAC/C,MAAM,WAAW,UAAU,MAAM,GAAG;CACpC,MAAM,cAAc,UAAU,WAAW,GAAG,IACxC,SAAS,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAC5B,SAAS,MAAM;CACpB,MAAM,UAAU,UAAU,MAAM,YAAY,MAAM;CAClD,OAAO;EAAE;EAAa,WAAW,YAAY,KAAK,MAAM,IAAI;CAAU;AACxE;;;;;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AS,mBAAmB;GACvE;GACA,cAAc,eAAe,WAAW;EAC1C,EAAE;EAGF,MAAM,eAAe,OAAO,YAC1B,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,YACF,CAAC,CACH;EAGA,MAAM,aAAa,OAAO,YACxB,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,iBAAiB,YAAY,CAC/B,CAAC,CACH;EAEA,MAAM,cAAc,EAClB,UAAU,QAAa,YAAiB;GACtC,OAAO,QAAQ,QAAQ;IACrB,GAAG,OAAO,QAAQ;IAClB,GAAG;GACL;GAEA,IAAI,OAAO,kBAAkB,YAC3B,OAAO,cAAc,QAAQ,OAAO;GAEtC,OAAO;EACT,EACF;EAcA,MAAM,cAAc,6CAAmB;GAXrC,GAAG;GACH,GAAG;GACH,WAAW;IACT,GAAI,WAAW,aAAa,CAAC;IAC7B,cAAc;KACZ,GAAI,WAAW,WAAW,gBAAgB,CAAC;KAC3C,GAAG;IACL;GACF;EAGgD,GAAG,EACnD,iBAAiB,yBACnB,CAAC;EAUD,uBAAuB,WAAW;EAElC,OAAO;CACT;AACF;;;;;;;;;;;AAcA,MAAa,cAAc,qBAAqB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
3
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
5
4
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverSideTranslations.cjs","names":["CYAN"],"sources":["../../src/serverSideTranslations.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\n\n/**\n * Drop-in replacement for next-i18next's `serverSideTranslations`.\n *\n * In next-i18next this function loads translation JSON files and injects\n * them as `_nextI18Next` props so `useTranslation` can hydrate on the client.\n *\n * With Intlayer all dictionaries are compiled at build time so no runtime\n * loading is needed. This function returns the minimal shape expected by\n * `appWithTranslation` / `useTranslation` for drop-in compatibility.\n *\n * @deprecated serverSideTranslations has no use case with intlayer.\n * Dictionaries are compiled at build time and loaded automatically.\n *\n * @param locale - The active locale (e.g. from `getStaticProps` context).\n * @param namespacesRequired - Namespace list; recorded but not loaded.\n * @param configOverride - Config override; recorded but not applied.\n *\n * @example\n * ```ts\n * export const getStaticProps = async ({ locale }) => ({\n * props: {\n * ...(await serverSideTranslations(locale, ['common'])),\n * },\n * });\n * ```\n */\nexport const serverSideTranslations = async (\n locale: string,\n namespacesRequired?: string[],\n configOverride?: Record<string, unknown>\n): Promise<{ _nextI18Next: Record<string, unknown> }> => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('serverSideTranslations', CYAN)} has no use case with intlayer. Dictionaries are compiled at build time and loaded automatically under the hood.`\n );\n }\n\n return {\n _nextI18Next: {\n initialLocale: locale,\n initialI18nStore: {},\n ns: namespacesRequired ?? ['common'],\n userConfig: configOverride ?? null,\n },\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"serverSideTranslations.cjs","names":["CYAN"],"sources":["../../src/serverSideTranslations.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\n\n/**\n * Drop-in replacement for next-i18next's `serverSideTranslations`.\n *\n * In next-i18next this function loads translation JSON files and injects\n * them as `_nextI18Next` props so `useTranslation` can hydrate on the client.\n *\n * With Intlayer all dictionaries are compiled at build time so no runtime\n * loading is needed. This function returns the minimal shape expected by\n * `appWithTranslation` / `useTranslation` for drop-in compatibility.\n *\n * @deprecated serverSideTranslations has no use case with intlayer.\n * Dictionaries are compiled at build time and loaded automatically.\n *\n * @param locale - The active locale (e.g. from `getStaticProps` context).\n * @param namespacesRequired - Namespace list; recorded but not loaded.\n * @param configOverride - Config override; recorded but not applied.\n *\n * @example\n * ```ts\n * export const getStaticProps = async ({ locale }) => ({\n * props: {\n * ...(await serverSideTranslations(locale, ['common'])),\n * },\n * });\n * ```\n */\nexport const serverSideTranslations = async (\n locale: string,\n namespacesRequired?: string[],\n configOverride?: Record<string, unknown>\n): Promise<{ _nextI18Next: Record<string, unknown> }> => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('serverSideTranslations', CYAN)} has no use case with intlayer. Dictionaries are compiled at build time and loaded automatically under the hood.`\n );\n }\n\n return {\n _nextI18Next: {\n initialLocale: locale,\n initialI18nStore: {},\n ns: namespacesRequired ?? ['common'],\n userConfig: configOverride ?? null,\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,yBAAyB,OACpC,QACA,oBACA,mBACuD;CACvD,IAAI,QAAQ,IAAI,aAAa,eAE3B,0CAD+B,EAAE,gCAAI,CAC7B,CAAC,CACP,yCAAY,0BAA0BA,4BAAI,EAAE,iHAC9C;CAGF,OAAO,EACL,cAAc;EACZ,eAAe;EACf,kBAAkB,CAAC;EACnB,IAAI,sBAAsB,CAAC,QAAQ;EACnC,YAAY,kBAAkB;CAChC,EACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appWithTranslation.mjs","names":[],"sources":["../../src/appWithTranslation.tsx"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { appWithTranslation as _appWithTranslation } from 'next-i18next/pages';\nimport type * as React from 'react';\nimport { IntlayerProvider } from 'react-intlayer';\n\n/**\n * Drop-in replacement for next-i18next's `appWithTranslation` HOC.\n *\n * Wraps the Next.js `App` component in `IntlayerProvider` and passes the\n * active locale from `_nextI18Next.initialLocale` or the Next.js router.\n *\n * @example\n * ```tsx\n * export default appWithTranslation(MyApp);\n * ```\n */\nexport const appWithTranslation: typeof _appWithTranslation = (\n WrappedApp,\n _configOverride?\n) => {\n const AppWithTranslation = (\n props: React.ComponentProps<typeof WrappedApp> & {\n pageProps: {\n _nextI18Next?: { initialLocale?: string };\n [key: string]: unknown;\n };\n router?: { locale?: string };\n }\n ) => {\n const locale: string | undefined =\n props.pageProps?._nextI18Next?.initialLocale ?? props.router?.locale;\n\n return (\n <IntlayerProvider locale={locale as LocalesValues}>\n <WrappedApp {...props} />\n </IntlayerProvider>\n );\n };\n\n AppWithTranslation.displayName = `appWithTranslation(${\n WrappedApp.displayName ?? WrappedApp.name ?? 'App'\n })`;\n\n return AppWithTranslation as unknown as ReturnType<\n typeof _appWithTranslation\n >;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,sBACX,YACA,oBACG;CACH,MAAM,sBACJ,UAOG;
|
|
1
|
+
{"version":3,"file":"appWithTranslation.mjs","names":[],"sources":["../../src/appWithTranslation.tsx"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { appWithTranslation as _appWithTranslation } from 'next-i18next/pages';\nimport type * as React from 'react';\nimport { IntlayerProvider } from 'react-intlayer';\n\n/**\n * Drop-in replacement for next-i18next's `appWithTranslation` HOC.\n *\n * Wraps the Next.js `App` component in `IntlayerProvider` and passes the\n * active locale from `_nextI18Next.initialLocale` or the Next.js router.\n *\n * @example\n * ```tsx\n * export default appWithTranslation(MyApp);\n * ```\n */\nexport const appWithTranslation: typeof _appWithTranslation = (\n WrappedApp,\n _configOverride?\n) => {\n const AppWithTranslation = (\n props: React.ComponentProps<typeof WrappedApp> & {\n pageProps: {\n _nextI18Next?: { initialLocale?: string };\n [key: string]: unknown;\n };\n router?: { locale?: string };\n }\n ) => {\n const locale: string | undefined =\n props.pageProps?._nextI18Next?.initialLocale ?? props.router?.locale;\n\n return (\n <IntlayerProvider locale={locale as LocalesValues}>\n <WrappedApp {...props} />\n </IntlayerProvider>\n );\n };\n\n AppWithTranslation.displayName = `appWithTranslation(${\n WrappedApp.displayName ?? WrappedApp.name ?? 'App'\n })`;\n\n return AppWithTranslation as unknown as ReturnType<\n typeof _appWithTranslation\n >;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,sBACX,YACA,oBACG;CACH,MAAM,sBACJ,UAOG;EAIH,OACE,oBAAC,kBAAD;GAAkB,QAHlB,MAAM,WAAW,cAAc,iBAAiB,MAAM,QAAQ;aAI5D,oBAAC,YAAD,EAAY,GAAI,MAAQ;EACR;CAEtB;CAEA,mBAAmB,cAAc,sBAC/B,WAAW,eAAe,WAAW,QAAQ,MAC9C;CAED,OAAO;AAGT"}
|
|
@@ -2,8 +2,9 @@ import * as ANSIColors from "@intlayer/config/colors";
|
|
|
2
2
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { REACT_I18NEXT_CALLERS, toSwcExtraCallers } from "@intlayer/config/callers";
|
|
6
6
|
import { getConfiguration } from "@intlayer/config/node";
|
|
7
|
+
import { runOnce } from "@intlayer/engine/utils";
|
|
7
8
|
import { withIntlayer } from "next-intlayer/server";
|
|
8
9
|
|
|
9
10
|
//#region src/plugin/index.ts
|
|
@@ -78,17 +79,12 @@ const resolveEsmPath = (specifier) => {
|
|
|
78
79
|
* @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.
|
|
79
80
|
*/
|
|
80
81
|
const toTurbopackAlias = (absolutePath) => `./${relative(process.cwd(), absolutePath).split(sep).join("/")}`;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
],
|
|
88
|
-
namespaceArgIndex: 0,
|
|
89
|
-
staticReplacement: "useDictionary",
|
|
90
|
-
dynamicReplacement: "useDictionaryDynamic"
|
|
91
|
-
}];
|
|
82
|
+
/**
|
|
83
|
+
* SWC extra-caller configs derived from the shared caller registry
|
|
84
|
+
* (`@intlayer/config/callers`) — the single source of truth also consumed by
|
|
85
|
+
* the babel analyzer/optimizer and the LSP.
|
|
86
|
+
*/
|
|
87
|
+
const NEXT_I18NEXT_SWC_CALLERS = toSwcExtraCallers(REACT_I18NEXT_CALLERS);
|
|
92
88
|
/**
|
|
93
89
|
* Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js
|
|
94
90
|
* config so the runtime dictionary registry stays populated. Mutates the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\nconst NEXT_I18NEXT_SWC_CALLERS = [\n {\n callerName: 'useTranslation',\n importSources: ['react-i18next', '@intlayer/react-i18next', 'next-i18next'],\n namespaceArgIndex: 0,\n staticReplacement: 'useDictionary',\n dynamicReplacement: 'useDictionaryDynamic',\n },\n];\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\n * export default withI18next(nextConfig);\n * ```\n */\nexport const withI18next = createNextI18nPlugin();\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,gBAAgB,cAAc,OAAO,KAAK,IAAI;;;;;AAMpD,MAAM,gBAA4D;CAChE;EAAE,SAAS;EAAgB,aAAa;EAA0B;CAClE;EAAE,SAAS;EAAiB,aAAa;EAA2B;CACpE;EAAE,SAAS;EAAW,aAAa;EAAqB;CACzD;;;;;;;;AASD,MAA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,MAAa,wBAAwB,cAAuB;AAC1D,QAAO,OAAO,aAAyB,EAAE,KAA0B;EACjE,MAAM,iBAAiB,kBAAkB;EACzC,MAAM,YAAY,aAAa,eAAe;AAE9C,UACE,KACE,eAAe,OAAO,SACtB,aACA,SACA,kCACD,QACK;AACJ,aAAU,CACR,SACE,+CACA,WAAW,KACZ,EACD,SACE,iDACA,WAAW,WACZ,CACF,CAAC;KAEJ,EACE,gBAAgB,MAAO,KAAK,IAC7B,CACF;EAED,MAAM,gBAAgB,WAAW;EAEjC,MAAM,kBAAkB,cAAc,KAAK,EAAE,SAAS,mBAAmB;GACvE;GACA,cAAc,eAAe,YAAY;GAC1C,EAAE;EAGH,MAAM,eAAe,OAAO,YAC1B,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,aACD,CAAC,CACH;EAGD,MAAM,aAAa,OAAO,YACxB,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,iBAAiB,aAAa,CAC/B,CAAC,CACH;EAED,MAAM,cAAc,EAClB,UAAU,QAAa,YAAiB;AACtC,UAAO,QAAQ,QAAQ;IACrB,GAAG,OAAO,QAAQ;IAClB,GAAG;IACJ;AAED,OAAI,OAAO,kBAAkB,WAC3B,QAAO,cAAc,QAAQ,QAAQ;AAEvC,UAAO;KAEV;EAcD,MAAM,cAAc,MAAM,aAAa;GAXrC,GAAG;GACH,GAAG;GACH,WAAW;IACT,GAAI,WAAW,aAAa,EAAE;IAC9B,cAAc;KACZ,GAAI,WAAW,WAAW,gBAAgB,EAAE;KAC5C,GAAG;KACJ;IACF;GAGgD,EAAE,EACnD,iBAAiB,0BAClB,CAAC;AAUF,yBAAuB,YAAY;AAEnC,SAAO;;;;;;;;;;;;;AAgBX,MAAa,cAAc,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport {\n REACT_I18NEXT_CALLERS,\n toSwcExtraCallers,\n} from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original import specifier (next-i18next, react-i18next, i18next) to\n * the `@intlayer/*` specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-i18next', replacement: '@intlayer/next-i18next' },\n { request: 'react-i18next', replacement: '@intlayer/react-i18next' },\n { request: 'i18next', replacement: '@intlayer/i18next' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/react-i18next` or `i18next`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/react-i18next`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/react-i18next/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\n/**\n * SWC extra-caller configs derived from the shared caller registry\n * (`@intlayer/config/callers`) — the single source of truth also consumed by\n * the babel analyzer/optimizer and the LSP.\n */\nconst NEXT_I18NEXT_SWC_CALLERS = toSwcExtraCallers(REACT_I18NEXT_CALLERS);\n\n/**\n * Disables the SWC `replaceDictionaryEntry` optimization on the resolved Next.js\n * config so the runtime dictionary registry stays populated. Mutates the\n * `@intlayer/swc` plugin options in place (both webpack and Turbopack read the\n * same `experimental.swcPlugins` entry).\n *\n * @param config - The Next.js config returned by `withIntlayer`.\n */\nconst keepDictionaryRegistry = (config: NextConfig): void => {\n const swcPlugins = (\n config.experimental as { swcPlugins?: unknown[] } | undefined\n )?.swcPlugins;\n if (!Array.isArray(swcPlugins)) return;\n\n for (const plugin of swcPlugins) {\n if (!Array.isArray(plugin)) continue;\n const [pluginPath, pluginOptions] = plugin as [unknown, unknown];\n if (\n typeof pluginPath === 'string' &&\n pluginPath.includes('@intlayer/swc') &&\n pluginOptions !== null &&\n typeof pluginOptions === 'object'\n ) {\n (pluginOptions as Record<string, unknown>).replaceDictionaryEntry = false;\n }\n }\n};\n\n/**\n * A Next.js plugin for next-i18next compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-i18next` imports are served by\n * `@intlayer/next-i18next`.\n */\nexport const createNextI18nPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n const finalConfig = await withIntlayer(mergedConfig, {\n swcExtraCallers: NEXT_I18NEXT_SWC_CALLERS,\n });\n\n // i18next exposes runtime namespace APIs (`i18n.getFixedT(locale, ns)`,\n // `t('ns:key')`) that resolve dictionaries at runtime through `getIntlayer`.\n // Unlike `useTranslation('ns')`, these are not statically analyzable, so the\n // SWC cannot rewrite them to direct dictionary imports. The build optimization\n // normally empties the runtime dictionary registry (`replaceDictionaryEntry`),\n // which would make those APIs fall back to raw keys on the server. Keeping the\n // registry populated restores them; statically analyzable call sites are still\n // rewritten to direct imports, so client bundles stay tree-shaken.\n keepDictionaryRegistry(finalConfig);\n\n return finalConfig;\n };\n};\n\nexport default createNextI18nPlugin;\n\n/**\n * A pre-instantiated Next.js plugin for next-i18next compat.\n * Wraps a NextConfig directly without requiring the factory call pattern.\n *\n * Usage:\n * ```ts\n * import { withI18next } from '@intlayer/next-i18next/plugin';\n * export default withI18next(nextConfig);\n * ```\n */\nexport const withI18next = createNextI18nPlugin();\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAM,gBAAgB,cAAc,OAAO,KAAK,GAAG;;;;;AAMnD,MAAM,gBAA4D;CAChE;EAAE,SAAS;EAAgB,aAAa;CAAyB;CACjE;EAAE,SAAS;EAAiB,aAAa;CAA0B;CACnE;EAAE,SAAS;EAAW,aAAa;CAAoB;AACzD;;;;;;;;AASA,MAAM,kBACJ,cAC+C;CAC/C,MAAM,WAAW,UAAU,MAAM,GAAG;CACpC,MAAM,cAAc,UAAU,WAAW,GAAG,IACxC,SAAS,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAC5B,SAAS,MAAM;CACpB,MAAM,UAAU,UAAU,MAAM,YAAY,MAAM;CAClD,OAAO;EAAE;EAAa,WAAW,YAAY,KAAK,MAAM,IAAI;CAAU;AACxE;;;;;;;;;;;;AAaA,MAAM,kBAAkB,cAA8B;CACpD,MAAM,EAAE,aAAa,cAAc,eAAe,SAAS;CAC3D,MAAM,cAAc,cAAc,GAAG,YAAY,cAAc;CAM/D,MAAM,aAAa,Q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SAAS,mBAAmB,CACjD,SACA,YACF,CAAC,CACH;EAGA,MAAM,aAAa,OAAO,YACxB,gBAAgB,KAAK,EAAE,SAAS,mBAAmB,CACjD,SACA,iBAAiB,YAAY,CAC/B,CAAC,CACH;EAEA,MAAM,cAAc,EAClB,UAAU,QAAa,YAAiB;GACtC,OAAO,QAAQ,QAAQ;IACrB,GAAG,OAAO,QAAQ;IAClB,GAAG;GACL;GAEA,IAAI,OAAO,kBAAkB,YAC3B,OAAO,cAAc,QAAQ,OAAO;GAEtC,OAAO;EACT,EACF;EAcA,MAAM,cAAc,MAAM,aAAa;GAXrC,GAAG;GACH,GAAG;GACH,WAAW;IACT,GAAI,WAAW,aAAa,CAAC;IAC7B,cAAc;KACZ,GAAI,WAAW,WAAW,gBAAgB,CAAC;KAC3C,GAAG;IACL;GACF;EAGgD,GAAG,EACnD,iBAAiB,yBACnB,CAAC;EAUD,uBAAuB,WAAW;EAElC,OAAO;CACT;AACF;;;;;;;;;;;AAcA,MAAa,cAAc,qBAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverSideTranslations.mjs","names":[],"sources":["../../src/serverSideTranslations.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\n\n/**\n * Drop-in replacement for next-i18next's `serverSideTranslations`.\n *\n * In next-i18next this function loads translation JSON files and injects\n * them as `_nextI18Next` props so `useTranslation` can hydrate on the client.\n *\n * With Intlayer all dictionaries are compiled at build time so no runtime\n * loading is needed. This function returns the minimal shape expected by\n * `appWithTranslation` / `useTranslation` for drop-in compatibility.\n *\n * @deprecated serverSideTranslations has no use case with intlayer.\n * Dictionaries are compiled at build time and loaded automatically.\n *\n * @param locale - The active locale (e.g. from `getStaticProps` context).\n * @param namespacesRequired - Namespace list; recorded but not loaded.\n * @param configOverride - Config override; recorded but not applied.\n *\n * @example\n * ```ts\n * export const getStaticProps = async ({ locale }) => ({\n * props: {\n * ...(await serverSideTranslations(locale, ['common'])),\n * },\n * });\n * ```\n */\nexport const serverSideTranslations = async (\n locale: string,\n namespacesRequired?: string[],\n configOverride?: Record<string, unknown>\n): Promise<{ _nextI18Next: Record<string, unknown> }> => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('serverSideTranslations', CYAN)} has no use case with intlayer. Dictionaries are compiled at build time and loaded automatically under the hood.`\n );\n }\n\n return {\n _nextI18Next: {\n initialLocale: locale,\n initialI18nStore: {},\n ns: namespacesRequired ?? ['common'],\n userConfig: configOverride ?? null,\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,yBAAyB,OACpC,QACA,oBACA,mBACuD;
|
|
1
|
+
{"version":3,"file":"serverSideTranslations.mjs","names":[],"sources":["../../src/serverSideTranslations.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\n\n/**\n * Drop-in replacement for next-i18next's `serverSideTranslations`.\n *\n * In next-i18next this function loads translation JSON files and injects\n * them as `_nextI18Next` props so `useTranslation` can hydrate on the client.\n *\n * With Intlayer all dictionaries are compiled at build time so no runtime\n * loading is needed. This function returns the minimal shape expected by\n * `appWithTranslation` / `useTranslation` for drop-in compatibility.\n *\n * @deprecated serverSideTranslations has no use case with intlayer.\n * Dictionaries are compiled at build time and loaded automatically.\n *\n * @param locale - The active locale (e.g. from `getStaticProps` context).\n * @param namespacesRequired - Namespace list; recorded but not loaded.\n * @param configOverride - Config override; recorded but not applied.\n *\n * @example\n * ```ts\n * export const getStaticProps = async ({ locale }) => ({\n * props: {\n * ...(await serverSideTranslations(locale, ['common'])),\n * },\n * });\n * ```\n */\nexport const serverSideTranslations = async (\n locale: string,\n namespacesRequired?: string[],\n configOverride?: Record<string, unknown>\n): Promise<{ _nextI18Next: Record<string, unknown> }> => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('serverSideTranslations', CYAN)} has no use case with intlayer. Dictionaries are compiled at build time and loaded automatically under the hood.`\n );\n }\n\n return {\n _nextI18Next: {\n initialLocale: locale,\n initialI18nStore: {},\n ns: namespacesRequired ?? ['common'],\n userConfig: configOverride ?? null,\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,yBAAyB,OACpC,QACA,oBACA,mBACuD;CAGrD,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,0BAA0B,IAAI,EAAE,iHAC9C;CAGF,OAAO,EACL,cAAc;EACZ,eAAe;EACf,kBAAkB,CAAC;EACnB,IAAI,sBAAsB,CAAC,QAAQ;EACnC,YAAY,kBAAkB;CAChC,EACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appWithTranslation.d.ts","names":[],"sources":["../../src/appWithTranslation.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"appWithTranslation.d.ts","names":[],"sources":["../../src/appWithTranslation.tsx"],"mappings":";;;;;;;;;;;;;cAgBa,2BAA2B"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { appWithTranslation } from "./appWithTranslation.js";
|
|
|
2
2
|
import { serverSideTranslations } from "./serverSideTranslations.js";
|
|
3
3
|
import { i18n as i18n$1 } from "@intlayer/i18next";
|
|
4
4
|
import { I18nContext, I18nextProvider, Trans, Translation, initReactI18next, useDictionary, useDictionaryDynamic, useTranslation, withTranslation } from "@intlayer/react-i18next";
|
|
5
|
-
|
|
6
5
|
//#region src/index.d.ts
|
|
7
6
|
declare const i18n: i18n$1;
|
|
8
7
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;cAEa,MAA6B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;;cAwIa,uBAAoB,wBAAsB,aAC3B,eAAkB,QAAQ;;;;;;;;;;;cA2GzC,cAAW,aA3GI,eAAkB,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverSideTranslations.d.ts","names":[],"sources":["../../src/serverSideTranslations.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"serverSideTranslations.d.ts","names":[],"sources":["../../src/serverSideTranslations.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;cA8Ba,yBAAsB,gBACnB,+BACe,iBACZ,4BAChB;EAAU,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/next-i18next",
|
|
3
|
-
"version": "9.0.0
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "next-i18next API adapter for intlayer — serverSideTranslations, appWithTranslation, useTranslation backed by next-intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -79,28 +79,28 @@
|
|
|
79
79
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@intlayer/
|
|
83
|
-
"@intlayer/
|
|
84
|
-
"@intlayer/
|
|
85
|
-
"@intlayer/i18next": "9.0.0
|
|
86
|
-
"@intlayer/react-i18next": "9.0.0
|
|
87
|
-
"@intlayer/types": "9.0.0
|
|
88
|
-
"next-intlayer": "9.0.0
|
|
89
|
-
"react-intlayer": "9.0.0
|
|
82
|
+
"@intlayer/config": "9.0.0",
|
|
83
|
+
"@intlayer/core": "9.0.0",
|
|
84
|
+
"@intlayer/engine": "9.0.0",
|
|
85
|
+
"@intlayer/i18next": "9.0.0",
|
|
86
|
+
"@intlayer/react-i18next": "9.0.0",
|
|
87
|
+
"@intlayer/types": "9.0.0",
|
|
88
|
+
"next-intlayer": "9.0.0",
|
|
89
|
+
"react-intlayer": "9.0.0"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"@types/node": "
|
|
92
|
+
"@types/node": "26.1.1",
|
|
93
93
|
"@types/react": "19.2.17",
|
|
94
94
|
"@utils/ts-config": "1.0.4",
|
|
95
95
|
"@utils/ts-config-types": "1.0.4",
|
|
96
96
|
"@utils/tsdown-config": "1.0.4",
|
|
97
|
-
"i18next": "26.3.
|
|
98
|
-
"next-i18next": "16.0.
|
|
99
|
-
"react-i18next": "17.0.
|
|
97
|
+
"i18next": "26.3.6",
|
|
98
|
+
"next-i18next": "16.0.8",
|
|
99
|
+
"react-i18next": "17.0.10",
|
|
100
100
|
"rimraf": "6.1.3",
|
|
101
|
-
"tsdown": "0.
|
|
102
|
-
"typescript": "
|
|
103
|
-
"vitest": "4.1.
|
|
101
|
+
"tsdown": "0.22.13",
|
|
102
|
+
"typescript": "7.0.2",
|
|
103
|
+
"vitest": "4.1.10"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"i18next": ">=20.0.0",
|