next-i18next 16.0.3 → 16.0.5
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/README.md
CHANGED
|
@@ -676,7 +676,8 @@ If you were using i18next and react-i18next directly (as recommended in v15):
|
|
|
676
676
|
|
|
677
677
|
1. Update imports from `next-i18next` to `next-i18next/pages`
|
|
678
678
|
2. Update `serverSideTranslations` import to `next-i18next/pages/serverSideTranslations`
|
|
679
|
-
3.
|
|
679
|
+
3. Update type imports: `import type { TFunction, WithTranslation, I18n } from 'next-i18next/pages'`
|
|
680
|
+
4. Everything else works the same
|
|
680
681
|
|
|
681
682
|
---
|
|
682
683
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createConfig.cjs","names":["defaultConfig","unique","getFallbackForLng"],"sources":["../../../src/pagesRouter/config/createConfig.ts"],"sourcesContent":["import { defaultConfig } from './defaultConfig'\nimport { InternalConfig, UserConfig } from '../types'\nimport { getFallbackForLng, unique } from '../utils'\nimport { FallbackLngObjList, Module } from 'i18next'\n\nconst deepMergeObjects = ['backend', 'detection'] as (keyof Pick<\n UserConfig,\n 'backend' | 'detection'\n>)[]\n\nexport const createConfig = (\n userConfig: UserConfig\n): InternalConfig => {\n if (typeof userConfig?.lng !== 'string') {\n throw new Error('config.lng was not passed into createConfig')\n }\n\n //\n // Initial merge of default and user-provided config\n //\n const { i18n: userI18n, ...userConfigStripped } = userConfig\n const { i18n: defaultI18n, ...defaultConfigStripped } =\n defaultConfig\n const combinedConfig = {\n ...defaultConfigStripped,\n ...userConfigStripped,\n ...defaultI18n,\n ...userI18n,\n }\n\n const {\n defaultNS,\n lng,\n localeExtension,\n localePath,\n nonExplicitSupportedLngs,\n } = combinedConfig\n\n const locales = combinedConfig.locales.filter((l: string) => l !== 'default')\n\n /**\n * Skips translation file resolution while in cimode\n * https://github.com/i18next/next-i18next/pull/851#discussion_r503113620\n */\n if (lng === 'cimode') {\n return combinedConfig as InternalConfig\n }\n\n if (typeof combinedConfig.fallbackLng === 'undefined') {\n combinedConfig.fallbackLng = combinedConfig.defaultLocale\n if (combinedConfig.fallbackLng === 'default') { [combinedConfig.fallbackLng] = locales }\n }\n\n const userPrefix = userConfig?.interpolation?.prefix\n const userSuffix = userConfig?.interpolation?.suffix\n const prefix = userPrefix ?? '{{'\n const suffix = userSuffix ?? '}}'\n if (\n typeof userConfig?.localeStructure !== 'string' &&\n (userPrefix || userSuffix)\n ) {\n combinedConfig.localeStructure = `${prefix}lng${suffix}/${prefix}ns${suffix}`\n }\n\n const { fallbackLng, localeStructure } = combinedConfig\n\n if (nonExplicitSupportedLngs) {\n const createFallbackObject = (\n acc: FallbackLngObjList,\n l: string\n ) => {\n const [locale] = l.split('-')\n acc[l] = [locale]\n return acc\n }\n\n if (typeof fallbackLng === 'string') {\n combinedConfig.fallbackLng = combinedConfig.locales\n .filter((l: string) => l.includes('-'))\n .reduce(createFallbackObject, { default: [fallbackLng] })\n } else if (Array.isArray(fallbackLng)) {\n combinedConfig.fallbackLng = combinedConfig.locales\n .filter((l: string) => l.includes('-'))\n .reduce(createFallbackObject, { default: fallbackLng })\n } else if (typeof fallbackLng === 'object') {\n combinedConfig.fallbackLng = Object.entries(\n combinedConfig.fallbackLng\n ).reduce<FallbackLngObjList>((acc, [l, f]: [string, any]) => {\n acc[l] = l.includes('-')\n ? unique([l.split('-')[0], ...f])\n : f\n return acc\n }, fallbackLng as FallbackLngObjList)\n } else if (typeof fallbackLng === 'function') {\n throw new Error(\n 'If nonExplicitSupportedLngs is true, no functions are allowed for fallbackLng'\n )\n }\n }\n\n const hasCustomBackend = userConfig?.use?.filter(Boolean).some(\n (b: Module) => b.type === 'backend'\n )\n if (!process.browser && typeof window === 'undefined') {\n combinedConfig.preload = locales\n\n if (!hasCustomBackend) {\n const fs = require('fs')\n const path = require('path')\n\n //\n // Validate defaultNS\n // https://github.com/i18next/next-i18next/issues/358\n //\n if (\n typeof defaultNS === 'string' &&\n typeof lng !== 'undefined'\n ) {\n if (typeof localePath === 'string') {\n const defaultLocaleStructure = localeStructure\n .replace(`${prefix}lng${suffix}`, lng)\n .replace(`${prefix}ns${suffix}`, defaultNS)\n const defaultFile = `/${defaultLocaleStructure}.${localeExtension}`\n const defaultNSPath = path.join(localePath, defaultFile)\n const defaultNSExists = fs.existsSync(defaultNSPath)\n const fallback = getFallbackForLng(\n lng,\n combinedConfig.fallbackLng\n )\n const defaultFallbackNSExists = fallback.some(f => {\n const fallbackFile = defaultFile.replace(lng, f)\n const defaultNSPath = path.join(localePath, fallbackFile)\n return fs.existsSync(defaultNSPath)\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(\n `Default namespace not found at ${defaultNSPath}`\n )\n }\n } else if (typeof localePath === 'function') {\n const defaultNSPath = localePath(lng, defaultNS, false)\n const defaultNSExists = fs.existsSync(defaultNSPath)\n const fallback = getFallbackForLng(\n lng,\n combinedConfig.fallbackLng\n )\n const defaultFallbackNSExists = fallback.some(f => {\n const defaultNSPath = localePath(f, defaultNS, false)\n return fs.existsSync(defaultNSPath)\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(\n `Default namespace not found at ${defaultNSPath}`\n )\n }\n }\n }\n\n //\n // Set server side backend\n //\n if (typeof localePath === 'string') {\n combinedConfig.backend = {\n addPath: path.resolve(\n process.cwd(),\n `${localePath}/${localeStructure}.missing.${localeExtension}`\n ),\n loadPath: path.resolve(\n process.cwd(),\n `${localePath}/${localeStructure}.${localeExtension}`\n ),\n }\n } else if (typeof localePath === 'function') {\n combinedConfig.backend = {\n addPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, true),\n loadPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, false),\n }\n } else if (localePath) {\n throw new Error(\n `Unsupported localePath type: ${typeof localePath}`\n )\n }\n\n //\n // Set server side preload (namespaces)\n //\n if (!combinedConfig.ns && typeof lng !== 'undefined') {\n if (typeof localePath === 'function') {\n throw new Error(\n 'Must provide all namespaces in ns option if using a function as localePath'\n )\n }\n\n const getNamespaces = (locales: string[]): string[] => {\n const getLocaleNamespaces = (p: string) => {\n let ret: string[] = []\n\n if (!fs.existsSync(p)) return ret\n\n fs.readdirSync(p).forEach((file: string) => {\n const joinedP = path.join(p, file)\n if (fs.statSync(joinedP).isDirectory()) {\n const subRet = getLocaleNamespaces(joinedP).map(\n n => `${file}/${n}`\n )\n ret = ret.concat(subRet)\n return\n }\n ret.push(file.replace(`.${localeExtension}`, ''))\n })\n return ret\n }\n\n let namespacesByLocale\n const r = combinedConfig.resources\n if (!localePath && r) {\n namespacesByLocale = locales.map(locale => Object.keys(r[locale]))\n } else {\n namespacesByLocale = locales.map(locale =>\n getLocaleNamespaces(\n path.resolve(process.cwd(), `${localePath}/${locale}`)\n )\n )\n }\n\n const allNamespaces = []\n for (const localNamespaces of namespacesByLocale) {\n allNamespaces.push(...localNamespaces)\n }\n\n return unique(allNamespaces)\n }\n\n if (\n localeStructure.indexOf(`${prefix}lng${suffix}`) >\n localeStructure.indexOf(`${prefix}ns${suffix}`)\n ) {\n throw new Error(\n 'Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns'\n )\n }\n\n combinedConfig.ns = getNamespaces(\n unique([\n lng,\n ...getFallbackForLng(lng, combinedConfig.fallbackLng),\n ])\n )\n }\n }\n } else {\n //\n // Set client side backend, if there is no custom backend\n //\n if (!hasCustomBackend) {\n if (typeof localePath === 'string') {\n combinedConfig.backend = {\n addPath: `${localePath}/${localeStructure}.missing.${localeExtension}`,\n loadPath: `${localePath}/${localeStructure}.${localeExtension}`,\n }\n } else if (typeof localePath === 'function') {\n combinedConfig.backend = {\n addPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, true),\n loadPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, false),\n }\n }\n }\n\n if (\n typeof combinedConfig.ns !== 'string' &&\n !Array.isArray(combinedConfig.ns)\n ) {\n combinedConfig.ns = [defaultNS as string]\n }\n }\n\n //\n // Deep merge with overwrite - goes last\n //\n deepMergeObjects.forEach(obj => {\n if (userConfig[obj]) {\n combinedConfig[obj] = {\n ...combinedConfig[obj],\n ...userConfig[obj],\n }\n }\n })\n\n return combinedConfig as InternalConfig\n}\n"],"mappings":";;;;AAKA,MAAM,mBAAmB,CAAC,WAAW,YAAY;AAKjD,MAAa,gBACX,eACmB;AACnB,KAAI,OAAO,YAAY,QAAQ,SAC7B,OAAM,IAAI,MAAM,8CAA8C;CAMhE,MAAM,EAAE,MAAM,UAAU,GAAG,uBAAuB;CAClD,MAAM,EAAE,MAAM,aAAa,GAAG,0BAC5BA,6BAAAA;CACF,MAAM,iBAAiB;EACrB,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACJ;CAED,MAAM,EACJ,WACA,KACA,iBACA,YACA,6BACE;CAEJ,MAAM,UAAU,eAAe,QAAQ,QAAQ,MAAc,MAAM,UAAU;;;;;AAM7E,KAAI,QAAQ,SACV,QAAO;AAGT,KAAI,OAAO,eAAe,gBAAgB,aAAa;AACrD,iBAAe,cAAc,eAAe;AAC5C,MAAI,eAAe,gBAAgB,UAAa,EAAC,eAAe,eAAe;;CAGjF,MAAM,aAAa,YAAY,eAAe;CAC9C,MAAM,aAAa,YAAY,eAAe;CAC9C,MAAM,SAAS,cAAc;CAC7B,MAAM,SAAS,cAAc;AAC7B,KACE,OAAO,YAAY,oBAAoB,aACtC,cAAc,YAEf,gBAAe,kBAAkB,GAAG,OAAO,KAAK,OAAO,GAAG,OAAO,IAAI;CAGvE,MAAM,EAAE,aAAa,oBAAoB;AAEzC,KAAI,0BAA0B;EAC5B,MAAM,wBACJ,KACA,MACG;GACH,MAAM,CAAC,UAAU,EAAE,MAAM,IAAI;AAC7B,OAAI,KAAK,CAAC,OAAO;AACjB,UAAO;;AAGT,MAAI,OAAO,gBAAgB,SACzB,gBAAe,cAAc,eAAe,QACzC,QAAQ,MAA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AAO;GACpB,GAAG,eAAe;GAClB,GAAG,WAAW;GACf;GAEH;AAEF,QAAO"}
|
|
1
|
+
{"version":3,"file":"createConfig.cjs","names":["defaultConfig","unique","getFallbackForLng"],"sources":["../../../src/pagesRouter/config/createConfig.ts"],"sourcesContent":["import { defaultConfig } from './defaultConfig'\nimport { InternalConfig, UserConfig } from '../types'\nimport { getFallbackForLng, unique } from '../utils'\nimport { FallbackLngObjList, Module } from 'i18next'\n\nconst deepMergeObjects = ['backend', 'detection'] as (keyof Pick<\n UserConfig,\n 'backend' | 'detection'\n>)[]\n\nexport const createConfig = (\n userConfig: UserConfig\n): InternalConfig => {\n if (typeof userConfig?.lng !== 'string') {\n throw new Error('config.lng was not passed into createConfig')\n }\n\n //\n // Initial merge of default and user-provided config\n //\n const { i18n: userI18n, ...userConfigStripped } = userConfig\n const { i18n: defaultI18n, ...defaultConfigStripped } =\n defaultConfig\n const combinedConfig = {\n ...defaultConfigStripped,\n ...userConfigStripped,\n ...defaultI18n,\n ...userI18n,\n }\n\n const {\n defaultNS,\n lng,\n localeExtension,\n localePath,\n nonExplicitSupportedLngs,\n } = combinedConfig\n\n const locales = combinedConfig.locales.filter((l: string) => l !== 'default')\n\n /**\n * Skips translation file resolution while in cimode\n * https://github.com/i18next/next-i18next/pull/851#discussion_r503113620\n */\n if (lng === 'cimode') {\n return combinedConfig as unknown as InternalConfig\n }\n\n if (typeof combinedConfig.fallbackLng === 'undefined') {\n combinedConfig.fallbackLng = combinedConfig.defaultLocale\n if (combinedConfig.fallbackLng === 'default') { [combinedConfig.fallbackLng] = locales }\n }\n\n const userPrefix = userConfig?.interpolation?.prefix\n const userSuffix = userConfig?.interpolation?.suffix\n const prefix = userPrefix ?? '{{'\n const suffix = userSuffix ?? '}}'\n if (\n typeof userConfig?.localeStructure !== 'string' &&\n (userPrefix || userSuffix)\n ) {\n combinedConfig.localeStructure = `${prefix}lng${suffix}/${prefix}ns${suffix}`\n }\n\n const { fallbackLng, localeStructure } = combinedConfig\n\n if (nonExplicitSupportedLngs) {\n const createFallbackObject = (\n acc: FallbackLngObjList,\n l: string\n ) => {\n const [locale] = l.split('-')\n acc[l] = [locale]\n return acc\n }\n\n if (typeof fallbackLng === 'string') {\n combinedConfig.fallbackLng = combinedConfig.locales\n .filter((l: string) => l.includes('-'))\n .reduce(createFallbackObject, { default: [fallbackLng] })\n } else if (Array.isArray(fallbackLng)) {\n combinedConfig.fallbackLng = combinedConfig.locales\n .filter((l: string) => l.includes('-'))\n .reduce(createFallbackObject, { default: fallbackLng })\n } else if (typeof fallbackLng === 'object') {\n combinedConfig.fallbackLng = Object.entries(\n combinedConfig.fallbackLng\n ).reduce<FallbackLngObjList>((acc, [l, f]: [string, any]) => {\n acc[l] = l.includes('-')\n ? unique([l.split('-')[0], ...f])\n : f\n return acc\n }, fallbackLng as FallbackLngObjList)\n } else if (typeof fallbackLng === 'function') {\n throw new Error(\n 'If nonExplicitSupportedLngs is true, no functions are allowed for fallbackLng'\n )\n }\n }\n\n const hasCustomBackend = userConfig?.use?.filter(Boolean).some(\n (b: Module) => b.type === 'backend'\n )\n if (!process.browser && typeof window === 'undefined') {\n combinedConfig.preload = locales\n\n if (!hasCustomBackend) {\n const fs = require('fs')\n const path = require('path')\n\n //\n // Validate defaultNS\n // https://github.com/i18next/next-i18next/issues/358\n //\n if (\n typeof defaultNS === 'string' &&\n typeof lng !== 'undefined'\n ) {\n if (typeof localePath === 'string') {\n const defaultLocaleStructure = localeStructure\n .replace(`${prefix}lng${suffix}`, lng)\n .replace(`${prefix}ns${suffix}`, defaultNS)\n const defaultFile = `/${defaultLocaleStructure}.${localeExtension}`\n const defaultNSPath = path.join(localePath, defaultFile)\n const defaultNSExists = fs.existsSync(defaultNSPath)\n const fallback = getFallbackForLng(\n lng,\n combinedConfig.fallbackLng\n )\n const defaultFallbackNSExists = fallback.some(f => {\n const fallbackFile = defaultFile.replace(lng, f)\n const defaultNSPath = path.join(localePath, fallbackFile)\n return fs.existsSync(defaultNSPath)\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(\n `Default namespace not found at ${defaultNSPath}`\n )\n }\n } else if (typeof localePath === 'function') {\n const defaultNSPath = localePath(lng, defaultNS, false)\n const defaultNSExists = fs.existsSync(defaultNSPath)\n const fallback = getFallbackForLng(\n lng,\n combinedConfig.fallbackLng\n )\n const defaultFallbackNSExists = fallback.some(f => {\n const defaultNSPath = localePath(f, defaultNS, false)\n return fs.existsSync(defaultNSPath)\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(\n `Default namespace not found at ${defaultNSPath}`\n )\n }\n }\n }\n\n //\n // Set server side backend\n //\n if (typeof localePath === 'string') {\n combinedConfig.backend = {\n addPath: path.resolve(\n process.cwd(),\n `${localePath}/${localeStructure}.missing.${localeExtension}`\n ),\n loadPath: path.resolve(\n process.cwd(),\n `${localePath}/${localeStructure}.${localeExtension}`\n ),\n }\n } else if (typeof localePath === 'function') {\n combinedConfig.backend = {\n addPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, true),\n loadPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, false),\n }\n } else if (localePath) {\n throw new Error(\n `Unsupported localePath type: ${typeof localePath}`\n )\n }\n\n //\n // Set server side preload (namespaces)\n //\n if (!combinedConfig.ns && typeof lng !== 'undefined') {\n if (typeof localePath === 'function') {\n throw new Error(\n 'Must provide all namespaces in ns option if using a function as localePath'\n )\n }\n\n const getNamespaces = (locales: string[]): string[] => {\n const getLocaleNamespaces = (p: string) => {\n let ret: string[] = []\n\n if (!fs.existsSync(p)) return ret\n\n fs.readdirSync(p).forEach((file: string) => {\n const joinedP = path.join(p, file)\n if (fs.statSync(joinedP).isDirectory()) {\n const subRet = getLocaleNamespaces(joinedP).map(\n n => `${file}/${n}`\n )\n ret = ret.concat(subRet)\n return\n }\n ret.push(file.replace(`.${localeExtension}`, ''))\n })\n return ret\n }\n\n let namespacesByLocale\n const r = combinedConfig.resources\n if (!localePath && r) {\n namespacesByLocale = locales.map(locale => Object.keys(r[locale]))\n } else {\n namespacesByLocale = locales.map(locale =>\n getLocaleNamespaces(\n path.resolve(process.cwd(), `${localePath}/${locale}`)\n )\n )\n }\n\n const allNamespaces = []\n for (const localNamespaces of namespacesByLocale) {\n allNamespaces.push(...localNamespaces)\n }\n\n return unique(allNamespaces)\n }\n\n if (\n localeStructure.indexOf(`${prefix}lng${suffix}`) >\n localeStructure.indexOf(`${prefix}ns${suffix}`)\n ) {\n throw new Error(\n 'Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns'\n )\n }\n\n combinedConfig.ns = getNamespaces(\n unique([\n lng,\n ...getFallbackForLng(lng, combinedConfig.fallbackLng),\n ])\n )\n }\n }\n } else {\n //\n // Set client side backend, if there is no custom backend\n //\n if (!hasCustomBackend) {\n if (typeof localePath === 'string') {\n combinedConfig.backend = {\n addPath: `${localePath}/${localeStructure}.missing.${localeExtension}`,\n loadPath: `${localePath}/${localeStructure}.${localeExtension}`,\n }\n } else if (typeof localePath === 'function') {\n combinedConfig.backend = {\n addPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, true),\n loadPath: (locale: string, namespace: string) =>\n localePath(locale, namespace, false),\n }\n }\n }\n\n if (\n typeof combinedConfig.ns !== 'string' &&\n !Array.isArray(combinedConfig.ns)\n ) {\n combinedConfig.ns = [defaultNS as string]\n }\n }\n\n //\n // Deep merge with overwrite - goes last\n //\n deepMergeObjects.forEach(obj => {\n if (userConfig[obj]) {\n combinedConfig[obj] = {\n ...combinedConfig[obj],\n ...userConfig[obj],\n }\n }\n })\n\n return combinedConfig as unknown as InternalConfig\n}\n"],"mappings":";;;;AAKA,MAAM,mBAAmB,CAAC,WAAW,YAAY;AAKjD,MAAa,gBACX,eACmB;AACnB,KAAI,OAAO,YAAY,QAAQ,SAC7B,OAAM,IAAI,MAAM,8CAA8C;CAMhE,MAAM,EAAE,MAAM,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AG,WAAW,GAAG,SAAS,CACvD,CACF;KAGH,MAAM,gBAAgB,EAAE;AACxB,UAAK,MAAM,mBAAmB,mBAC5B,eAAc,KAAK,GAAG,gBAAgB;AAGxC,YAAOD,cAAAA,OAAO,cAAc;;AAG9B,QACE,gBAAgB,QAAQ,GAAG,OAAO,KAAK,SAAS,GAChD,gBAAgB,QAAQ,GAAG,OAAO,IAAI,SAAS,CAE/C,OAAM,IAAI,MACR,iHACD;AAGH,mBAAe,KAAK,cAClBA,cAAAA,OAAO,CACL,KACA,GAAGC,cAAAA,kBAAkB,KAAK,eAAe,YAAY,CACtD,CAAC,CACH;;;QAGA;AAIL,MAAI,CAAC;OACC,OAAO,eAAe,SACxB,gBAAe,UAAU;IACvB,SAAS,GAAG,WAAW,GAAG,gBAAgB,WAAW;IACrD,UAAU,GAAG,WAAW,GAAG,gBAAgB,GAAG;IAC/C;YACQ,OAAO,eAAe,WAC/B,gBAAe,UAAU;IACvB,UAAU,QAAgB,cACxB,WAAW,QAAQ,WAAW,KAAK;IACrC,WAAW,QAAgB,cACzB,WAAW,QAAQ,WAAW,MAAM;IACvC;;AAIL,MACE,OAAO,eAAe,OAAO,YAC7B,CAAC,MAAM,QAAQ,eAAe,GAAG,CAEjC,gBAAe,KAAK,CAAC,UAAoB;;AAO7C,kBAAiB,SAAQ,QAAO;AAC9B,MAAI,WAAW,KACb,gBAAe,OAAO;GACpB,GAAG,eAAe;GAClB,GAAG,WAAW;GACf;GAEH;AAEF,QAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SSRConfig, UserConfig } from "./types.cjs";
|
|
1
|
+
import { I18n, SSRConfig, TFunction, UseTranslation, UserConfig, WithTranslation, WithTranslationHocType } from "./types.cjs";
|
|
2
2
|
import { appWithTranslation, globalI18n } from "./appWithTranslation.cjs";
|
|
3
3
|
import { I18nContext, Trans, Translation, useTranslation, withTranslation } from "react-i18next";
|
|
4
|
-
export { I18nContext, type SSRConfig, Trans, Translation, type UserConfig, appWithTranslation, globalI18n as i18n, useTranslation, withTranslation };
|
|
4
|
+
export { type I18n, I18nContext, type SSRConfig, type TFunction, Trans, Translation, type UseTranslation, type UserConfig, type WithTranslation, type WithTranslationHocType, appWithTranslation, globalI18n as i18n, useTranslation, withTranslation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-i18next",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.5",
|
|
4
4
|
"repository": "git@github.com:i18next/next-i18next.git",
|
|
5
5
|
"author": "i18next",
|
|
6
6
|
"funding": [
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
"gh-release": "7.0.2",
|
|
172
172
|
"globals": "17.4.0",
|
|
173
173
|
"husky": "^9.0.0",
|
|
174
|
-
"i18next": "^
|
|
174
|
+
"i18next": "^26.0.1",
|
|
175
175
|
"jest": "^30.0.0",
|
|
176
176
|
"jest-environment-jsdom": "^30.0.0",
|
|
177
177
|
"neostandard": "^0.13.0",
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
"prettier": "3.8.1",
|
|
181
181
|
"react": "^19.2.4",
|
|
182
182
|
"react-dom": "^19.2.4",
|
|
183
|
-
"react-i18next": "^
|
|
183
|
+
"react-i18next": "^17.0.1",
|
|
184
184
|
"rimraf": "^6.1.3",
|
|
185
185
|
"start-server-and-test": "^2.1.5",
|
|
186
186
|
"tsdown": "0.21.4",
|