next-i18next 16.0.6 → 16.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +4 -0
  2. package/dist/pagesRouter/appWithTranslation.d.mts +15 -0
  3. package/dist/pagesRouter/appWithTranslation.mjs +74 -0
  4. package/dist/pagesRouter/appWithTranslation.mjs.map +1 -0
  5. package/dist/pagesRouter/config/createConfig.cjs +2 -64
  6. package/dist/pagesRouter/config/createConfig.cjs.map +1 -1
  7. package/dist/pagesRouter/config/createConfig.d.cts +4 -1
  8. package/dist/pagesRouter/config/createConfig.d.mts +10 -0
  9. package/dist/pagesRouter/config/createConfig.mjs +73 -0
  10. package/dist/pagesRouter/config/createConfig.mjs.map +1 -0
  11. package/dist/pagesRouter/config/defaultConfig.d.mts +27 -0
  12. package/dist/pagesRouter/config/defaultConfig.mjs +27 -0
  13. package/dist/pagesRouter/config/defaultConfig.mjs.map +1 -0
  14. package/dist/pagesRouter/config/serverSideConfig.cjs +78 -0
  15. package/dist/pagesRouter/config/serverSideConfig.cjs.map +1 -0
  16. package/dist/pagesRouter/config/serverSideConfig.d.cts +7 -0
  17. package/dist/pagesRouter/config/serverSideConfig.d.mts +7 -0
  18. package/dist/pagesRouter/config/serverSideConfig.mjs +74 -0
  19. package/dist/pagesRouter/config/serverSideConfig.mjs.map +1 -0
  20. package/dist/pagesRouter/createClient/browser.d.mts +7 -0
  21. package/dist/pagesRouter/createClient/browser.mjs +20 -0
  22. package/dist/pagesRouter/createClient/browser.mjs.map +1 -0
  23. package/dist/pagesRouter/createClient/node.cjs +2 -2
  24. package/dist/pagesRouter/createClient/node.d.mts +7 -0
  25. package/dist/pagesRouter/createClient/node.mjs +44 -0
  26. package/dist/pagesRouter/createClient/node.mjs.map +1 -0
  27. package/dist/pagesRouter/index.d.mts +4 -0
  28. package/dist/pagesRouter/index.mjs +3 -0
  29. package/dist/pagesRouter/serverSideTranslations.cjs +3 -2
  30. package/dist/pagesRouter/serverSideTranslations.cjs.map +1 -1
  31. package/dist/pagesRouter/serverSideTranslations.d.mts +9 -0
  32. package/dist/pagesRouter/serverSideTranslations.mjs +57 -0
  33. package/dist/pagesRouter/serverSideTranslations.mjs.map +1 -0
  34. package/dist/pagesRouter/types.d.mts +59 -0
  35. package/dist/pagesRouter/types.mjs +4 -0
  36. package/dist/pagesRouter/utils.d.mts +17 -0
  37. package/dist/pagesRouter/utils.mjs +26 -0
  38. package/dist/pagesRouter/utils.mjs.map +1 -0
  39. package/package.json +17 -5
package/README.md CHANGED
@@ -18,6 +18,10 @@ If you already know i18next: next-i18next v16 is a thin layer on top of [i18next
18
18
  - **Edge-safe Proxy**: Zero Node.js dependencies in the proxy/middleware path
19
19
  - **Pages Router**: Existing `appWithTranslation` / `serverSideTranslations` API preserved under `next-i18next/pages`
20
20
 
21
+ ## Advice:
22
+
23
+ If you don't like to manage your translation files manually or are simply looking for a [better management solution](https://www.locize.com?utm_source=next_i18next_readme&utm_medium=github&utm_campaign=readme), take a look at [i18next-locize-backend](https://github.com/locize/i18next-locize-backend). The i18next [backend plugin](https://www.i18next.com/overview/plugins-and-utils#backends) for 🌐 [Locize](https://www.locize.com?utm_source=next_i18next_readme&utm_medium=github&utm_campaign=readme) ☁️ — built by the same team behind next-i18next, with CDN delivery (works great on Vercel/serverless), AI translation, and no redeploys for copy changes.
24
+
21
25
  ---
22
26
 
23
27
  ## Table of Contents
@@ -0,0 +1,15 @@
1
+ import { SSRConfig, UserConfig } from "./types.mjs";
2
+ import React from "react";
3
+ import hoistNonReactStatics from "hoist-non-react-statics";
4
+ import { Trans, useTranslation, withTranslation } from "react-i18next";
5
+ import { i18n } from "i18next";
6
+ import { AppProps } from "next/app";
7
+
8
+ //#region src/pagesRouter/appWithTranslation.d.ts
9
+ declare let globalI18n: i18n | null;
10
+ declare const appWithTranslation: <Props extends AppProps>(WrappedComponent: React.ComponentType<Props>, configOverride?: UserConfig | null) => ((props: Props & {
11
+ pageProps: Props["pageProps"] & SSRConfig;
12
+ }) => React.JSX.Element) & hoistNonReactStatics.NonReactStatics<React.ComponentType<Props>, {}>;
13
+ //#endregion
14
+ export { Trans, appWithTranslation, globalI18n, useTranslation, withTranslation };
15
+ //# sourceMappingURL=appWithTranslation.d.mts.map
@@ -0,0 +1,74 @@
1
+ import { useIsomorphicLayoutEffect } from "./utils.mjs";
2
+ import { createConfig } from "./config/createConfig.mjs";
3
+ import browser_default from "./createClient/browser.mjs";
4
+ import React, { useMemo, useRef } from "react";
5
+ import hoistNonReactStatics from "hoist-non-react-statics";
6
+ import { I18nextProvider, Trans, useTranslation, withTranslation } from "react-i18next";
7
+ //#region src/pagesRouter/appWithTranslation.tsx
8
+ let globalI18n = null;
9
+ const addResourcesToI18next = (instance, resources) => {
10
+ if (resources && instance.isInitialized) {
11
+ for (const locale of Object.keys(resources)) for (const ns of Object.keys(resources[locale])) if (!instance?.store?.data || !instance.store.data[locale] || !instance.store.data[locale][ns]) instance.addResourceBundle(locale, ns, resources[locale][ns], true, true);
12
+ }
13
+ };
14
+ const appWithTranslation = (WrappedComponent, configOverride = null) => {
15
+ const AppWithTranslation = (props) => {
16
+ const { _nextI18Next } = props.pageProps || {};
17
+ let locale = _nextI18Next?.initialLocale ?? props?.router?.locale;
18
+ const ns = _nextI18Next?.ns;
19
+ const instanceRef = useRef(null);
20
+ /**
21
+ * Memoize i18n instance and reuse it rather than creating new instance.
22
+ * When the locale or resources are changed after instance was created,
23
+ * we will update the instance by calling addResourceBundle method on it.
24
+ */
25
+ const i18n = useMemo(() => {
26
+ if (!_nextI18Next && !configOverride) return null;
27
+ const userConfig = configOverride ?? _nextI18Next?.userConfig;
28
+ if (!userConfig) throw new Error("appWithTranslation was called without a next-i18next config");
29
+ if (!userConfig?.i18n) throw new Error("appWithTranslation was called without config.i18n");
30
+ if (!userConfig?.i18n?.defaultLocale) throw new Error("config.i18n does not include a defaultLocale property");
31
+ const { initialI18nStore } = _nextI18Next || {};
32
+ const resources = configOverride?.resources ?? initialI18nStore;
33
+ if (!locale) locale = userConfig.i18n.defaultLocale;
34
+ let instance = instanceRef.current;
35
+ if (instance) addResourcesToI18next(instance, resources);
36
+ else {
37
+ instance = browser_default({
38
+ ...createConfig({
39
+ ...userConfig,
40
+ lng: locale
41
+ }),
42
+ lng: locale,
43
+ ...ns && { ns },
44
+ resources
45
+ }).i18n;
46
+ addResourcesToI18next(instance, resources);
47
+ globalI18n = instance;
48
+ instanceRef.current = instance;
49
+ }
50
+ return instance;
51
+ }, [
52
+ _nextI18Next,
53
+ locale,
54
+ ns
55
+ ]);
56
+ /**
57
+ * Since calling changeLanguage method on existing i18n instance cause state update in react,
58
+ * we need to call the method in `useLayoutEffect` to prevent state update in render phase.
59
+ */
60
+ useIsomorphicLayoutEffect(() => {
61
+ if (!i18n || !locale) return;
62
+ i18n.changeLanguage(locale);
63
+ }, [i18n, locale]);
64
+ return i18n !== null ? /* @__PURE__ */ React.createElement(I18nextProvider, { i18n }, /* @__PURE__ */ React.createElement(WrappedComponent, props)) : /* @__PURE__ */ React.createElement(WrappedComponent, {
65
+ key: locale,
66
+ ...props
67
+ });
68
+ };
69
+ return hoistNonReactStatics(AppWithTranslation, WrappedComponent);
70
+ };
71
+ //#endregion
72
+ export { Trans, appWithTranslation, globalI18n, useTranslation, withTranslation };
73
+
74
+ //# sourceMappingURL=appWithTranslation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appWithTranslation.mjs","names":["createClient"],"sources":["../../src/pagesRouter/appWithTranslation.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react'\nimport hoistNonReactStatics from 'hoist-non-react-statics'\nimport { I18nextProvider } from 'react-i18next'\nimport type { AppProps as NextJsAppProps } from 'next/app'\n\nimport { createConfig } from './config/createConfig'\nimport createClient from './createClient/browser'\n\nimport { SSRConfig, UserConfig } from './types'\n\nimport { i18n as I18NextClient, Resource } from 'i18next'\nimport { useIsomorphicLayoutEffect } from './utils'\nexport {\n Trans,\n useTranslation,\n withTranslation,\n} from 'react-i18next'\n\nexport let globalI18n: I18NextClient | null = null\n\nconst addResourcesToI18next = (instance: I18NextClient, resources: Resource) => {\n if (resources && instance.isInitialized) {\n for (const locale of Object.keys(resources)) {\n for (const ns of Object.keys(resources[locale])) {\n if (!instance?.store?.data || !instance.store.data[locale] || !instance.store.data[locale][ns]) {\n instance.addResourceBundle(\n locale,\n ns,\n resources[locale][ns],\n true,\n true\n )\n }\n }\n }\n }\n}\n\nexport const appWithTranslation = <Props extends NextJsAppProps>(\n WrappedComponent: React.ComponentType<Props>,\n configOverride: UserConfig | null = null\n) => {\n const AppWithTranslation = (\n props: Props & { pageProps: Props['pageProps'] & SSRConfig }\n ) => {\n const { _nextI18Next } = props.pageProps || {} // pageProps may be undefined on strange setups, i.e. https://github.com/i18next/next-i18next/issues/2109\n let locale: string | undefined =\n _nextI18Next?.initialLocale ?? props?.router?.locale\n const ns = _nextI18Next?.ns\n\n const instanceRef = useRef<I18NextClient | null>(null)\n\n /**\n * Memoize i18n instance and reuse it rather than creating new instance.\n * When the locale or resources are changed after instance was created,\n * we will update the instance by calling addResourceBundle method on it.\n */\n const i18n: I18NextClient | null = useMemo(() => {\n if (!_nextI18Next && !configOverride) return null\n\n const userConfig = configOverride ?? _nextI18Next?.userConfig\n\n if (!userConfig) {\n throw new Error(\n 'appWithTranslation was called without a next-i18next config'\n )\n }\n\n if (!userConfig?.i18n) {\n throw new Error(\n 'appWithTranslation was called without config.i18n'\n )\n }\n\n if (!userConfig?.i18n?.defaultLocale) {\n throw new Error(\n 'config.i18n does not include a defaultLocale property'\n )\n }\n\n const { initialI18nStore } = _nextI18Next || {}\n const resources = configOverride?.resources ?? initialI18nStore\n\n if (!locale) locale = userConfig.i18n.defaultLocale\n\n let instance = instanceRef.current\n if (instance) {\n addResourcesToI18next(instance, resources)\n } else {\n instance = createClient({\n ...createConfig({\n ...userConfig,\n lng: locale,\n }),\n lng: locale,\n ...(ns && { ns }),\n resources,\n }).i18n\n\n addResourcesToI18next(instance, resources)\n\n globalI18n = instance\n instanceRef.current = instance\n }\n\n return instance\n }, [_nextI18Next, locale, ns])\n\n /**\n * Since calling changeLanguage method on existing i18n instance cause state update in react,\n * we need to call the method in `useLayoutEffect` to prevent state update in render phase.\n */\n useIsomorphicLayoutEffect(() => {\n if (!i18n || !locale) return\n i18n.changeLanguage(locale)\n }, [i18n, locale])\n\n return i18n !== null\n ? (\n <I18nextProvider i18n={i18n}>\n <WrappedComponent {...props} />\n </I18nextProvider>\n )\n : (\n <WrappedComponent key={locale} {...props} />\n )\n }\n\n return hoistNonReactStatics(AppWithTranslation, WrappedComponent)\n}\n"],"mappings":";;;;;;;AAkBA,IAAW,aAAmC;AAE9C,MAAM,yBAAyB,UAAyB,cAAwB;AAC9E,KAAI,aAAa,SAAS;OACnB,MAAM,UAAU,OAAO,KAAK,UAAU,CACzC,MAAK,MAAM,MAAM,OAAO,KAAK,UAAU,QAAQ,CAC7C,KAAI,CAAC,UAAU,OAAO,QAAQ,CAAC,SAAS,MAAM,KAAK,WAAW,CAAC,SAAS,MAAM,KAAK,QAAQ,IACzF,UAAS,kBACP,QACA,IACA,UAAU,QAAQ,KAClB,MACA,KACD;;;AAOX,MAAa,sBACX,kBACA,iBAAoC,SACjC;CACH,MAAM,sBACJ,UACG;EACH,MAAM,EAAE,iBAAiB,MAAM,aAAa,EAAE;EAC9C,IAAI,SACF,cAAc,iBAAiB,OAAO,QAAQ;EAChD,MAAM,KAAK,cAAc;EAEzB,MAAM,cAAc,OAA6B,KAAK;;;;;;EAOtD,MAAM,OAA6B,cAAc;AAC/C,OAAI,CAAC,gBAAgB,CAAC,eAAgB,QAAO;GAE7C,MAAM,aAAa,kBAAkB,cAAc;AAEnD,OAAI,CAAC,WACH,OAAM,IAAI,MACR,8DACD;AAGH,OAAI,CAAC,YAAY,KACf,OAAM,IAAI,MACR,oDACD;AAGH,OAAI,CAAC,YAAY,MAAM,cACrB,OAAM,IAAI,MACR,wDACD;GAGH,MAAM,EAAE,qBAAqB,gBAAgB,EAAE;GAC/C,MAAM,YAAY,gBAAgB,aAAa;AAE/C,OAAI,CAAC,OAAQ,UAAS,WAAW,KAAK;GAEtC,IAAI,WAAW,YAAY;AAC3B,OAAI,SACF,uBAAsB,UAAU,UAAU;QACrC;AACL,eAAWA,gBAAa;KACtB,GAAG,aAAa;MACd,GAAG;MACH,KAAK;MACN,CAAC;KACF,KAAK;KACL,GAAI,MAAM,EAAE,IAAI;KAChB;KACD,CAAC,CAAC;AAEH,0BAAsB,UAAU,UAAU;AAE1C,iBAAa;AACb,gBAAY,UAAU;;AAGxB,UAAO;KACN;GAAC;GAAc;GAAQ;GAAG,CAAC;;;;;AAM9B,kCAAgC;AAC9B,OAAI,CAAC,QAAQ,CAAC,OAAQ;AACtB,QAAK,eAAe,OAAO;KAC1B,CAAC,MAAM,OAAO,CAAC;AAElB,SAAO,SAAS,OAEZ,sBAAA,cAAC,iBAAD,EAAuB,MAEL,EADhB,sBAAA,cAAC,kBAAqB,MAAS,CACf,GAGlB,sBAAA,cAAC,kBAAD;GAAkB,KAAK;GAAQ,GAAI;GAAS,CAAA;;AAIlD,QAAO,qBAAqB,oBAAoB,iBAAiB"}
@@ -3,7 +3,7 @@ const require_config_defaultConfig = require("./defaultConfig.cjs");
3
3
  const require_utils = require("../utils.cjs");
4
4
  //#region src/pagesRouter/config/createConfig.ts
5
5
  const deepMergeObjects = ["backend", "detection"];
6
- const createConfig = (userConfig) => {
6
+ const createConfig = (userConfig, options = {}) => {
7
7
  if (typeof userConfig?.lng !== "string") throw new Error("config.lng was not passed into createConfig");
8
8
  const { i18n: userI18n, ...userConfigStripped } = userConfig;
9
9
  const { i18n: defaultI18n, ...defaultConfigStripped } = require_config_defaultConfig.defaultConfig;
@@ -46,69 +46,7 @@ const createConfig = (userConfig) => {
46
46
  }
47
47
  const hasCustomBackend = userConfig?.use?.filter(Boolean).some((b) => b.type === "backend");
48
48
  if (!process.browser && typeof window === "undefined") {
49
- combinedConfig.preload = locales;
50
- if (!hasCustomBackend) {
51
- const fs = require("fs");
52
- const path = require("path");
53
- if (typeof defaultNS === "string" && typeof lng !== "undefined") {
54
- if (typeof localePath === "string") {
55
- const defaultFile = `/${localeStructure.replace(`${prefix}lng${suffix}`, lng).replace(`${prefix}ns${suffix}`, defaultNS)}.${localeExtension}`;
56
- const defaultNSPath = path.join(localePath, defaultFile);
57
- const defaultNSExists = fs.existsSync(defaultNSPath);
58
- const defaultFallbackNSExists = require_utils.getFallbackForLng(lng, combinedConfig.fallbackLng).some((f) => {
59
- const fallbackFile = defaultFile.replace(lng, f);
60
- const defaultNSPath = path.join(localePath, fallbackFile);
61
- return fs.existsSync(defaultNSPath);
62
- });
63
- if (!defaultNSExists && !defaultFallbackNSExists && process.env.NODE_ENV !== "production") throw new Error(`Default namespace not found at ${defaultNSPath}`);
64
- } else if (typeof localePath === "function") {
65
- const defaultNSPath = localePath(lng, defaultNS, false);
66
- const defaultNSExists = fs.existsSync(defaultNSPath);
67
- const defaultFallbackNSExists = require_utils.getFallbackForLng(lng, combinedConfig.fallbackLng).some((f) => {
68
- const defaultNSPath = localePath(f, defaultNS, false);
69
- return fs.existsSync(defaultNSPath);
70
- });
71
- if (!defaultNSExists && !defaultFallbackNSExists && process.env.NODE_ENV !== "production") throw new Error(`Default namespace not found at ${defaultNSPath}`);
72
- }
73
- }
74
- if (typeof localePath === "string") combinedConfig.backend = {
75
- addPath: path.resolve(process.cwd(), `${localePath}/${localeStructure}.missing.${localeExtension}`),
76
- loadPath: path.resolve(process.cwd(), `${localePath}/${localeStructure}.${localeExtension}`)
77
- };
78
- else if (typeof localePath === "function") combinedConfig.backend = {
79
- addPath: (locale, namespace) => localePath(locale, namespace, true),
80
- loadPath: (locale, namespace) => localePath(locale, namespace, false)
81
- };
82
- else if (localePath) throw new Error(`Unsupported localePath type: ${typeof localePath}`);
83
- if (!combinedConfig.ns && typeof lng !== "undefined") {
84
- if (typeof localePath === "function") throw new Error("Must provide all namespaces in ns option if using a function as localePath");
85
- const getNamespaces = (locales) => {
86
- const getLocaleNamespaces = (p) => {
87
- let ret = [];
88
- if (!fs.existsSync(p)) return ret;
89
- fs.readdirSync(p).forEach((file) => {
90
- const joinedP = path.join(p, file);
91
- if (fs.statSync(joinedP).isDirectory()) {
92
- const subRet = getLocaleNamespaces(joinedP).map((n) => `${file}/${n}`);
93
- ret = ret.concat(subRet);
94
- return;
95
- }
96
- ret.push(file.replace(`.${localeExtension}`, ""));
97
- });
98
- return ret;
99
- };
100
- let namespacesByLocale;
101
- const r = combinedConfig.resources;
102
- if (!localePath && r) namespacesByLocale = locales.map((locale) => Object.keys(r[locale]));
103
- else namespacesByLocale = locales.map((locale) => getLocaleNamespaces(path.resolve(process.cwd(), `${localePath}/${locale}`)));
104
- const allNamespaces = [];
105
- for (const localNamespaces of namespacesByLocale) allNamespaces.push(...localNamespaces);
106
- return require_utils.unique(allNamespaces);
107
- };
108
- if (localeStructure.indexOf(`${prefix}lng${suffix}`) > localeStructure.indexOf(`${prefix}ns${suffix}`)) throw new Error("Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns");
109
- combinedConfig.ns = getNamespaces(require_utils.unique([lng, ...require_utils.getFallbackForLng(lng, combinedConfig.fallbackLng)]));
110
- }
111
- }
49
+ if (options.applyServerSideConfig) options.applyServerSideConfig(combinedConfig, userConfig);
112
50
  } else {
113
51
  if (!hasCustomBackend) {
114
52
  if (typeof localePath === "string") combinedConfig.backend = {
@@ -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 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,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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A;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
+ {"version":3,"file":"createConfig.cjs","names":["defaultConfig","unique"],"sources":["../../../src/pagesRouter/config/createConfig.ts"],"sourcesContent":["import { defaultConfig } from './defaultConfig'\nimport { InternalConfig, UserConfig } from '../types'\nimport { unique } from '../utils'\nimport { FallbackLngObjList, Module } from 'i18next'\n\nconst deepMergeObjects = ['backend', 'detection'] as (keyof Pick<\n UserConfig,\n 'backend' | 'detection'\n>)[]\n\ntype CreateConfigOptions = {\n // Hook called only on the server side. Kept as an injected dependency so\n // `createConfig` itself never references Node built-ins (`fs`, `path`,\n // `module`) and stays safe to bundle for the browser. Wired up by\n // `serverSideTranslations`, which is server-only.\n applyServerSideConfig?: (\n combinedConfig: any,\n userConfig: UserConfig\n ) => void\n}\n\nexport const createConfig = (\n userConfig: UserConfig,\n options: CreateConfigOptions = {}\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 if (options.applyServerSideConfig) {\n options.applyServerSideConfig(combinedConfig, userConfig)\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;AAgBjD,MAAa,gBACX,YACA,UAA+B,EAAE,KACd;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,gBAA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gB,WAAW;QAEtD;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,7 +1,10 @@
1
1
  import { InternalConfig, UserConfig } from "../types.cjs";
2
2
 
3
3
  //#region src/pagesRouter/config/createConfig.d.ts
4
- declare const createConfig: (userConfig: UserConfig) => InternalConfig;
4
+ type CreateConfigOptions = {
5
+ applyServerSideConfig?: (combinedConfig: any, userConfig: UserConfig) => void;
6
+ };
7
+ declare const createConfig: (userConfig: UserConfig, options?: CreateConfigOptions) => InternalConfig;
5
8
  //#endregion
6
9
  export { createConfig };
7
10
  //# sourceMappingURL=createConfig.d.cts.map
@@ -0,0 +1,10 @@
1
+ import { InternalConfig, UserConfig } from "../types.mjs";
2
+
3
+ //#region src/pagesRouter/config/createConfig.d.ts
4
+ type CreateConfigOptions = {
5
+ applyServerSideConfig?: (combinedConfig: any, userConfig: UserConfig) => void;
6
+ };
7
+ declare const createConfig: (userConfig: UserConfig, options?: CreateConfigOptions) => InternalConfig;
8
+ //#endregion
9
+ export { createConfig };
10
+ //# sourceMappingURL=createConfig.d.mts.map
@@ -0,0 +1,73 @@
1
+ import { defaultConfig } from "./defaultConfig.mjs";
2
+ import { unique } from "../utils.mjs";
3
+ //#region src/pagesRouter/config/createConfig.ts
4
+ const deepMergeObjects = ["backend", "detection"];
5
+ const createConfig = (userConfig, options = {}) => {
6
+ if (typeof userConfig?.lng !== "string") throw new Error("config.lng was not passed into createConfig");
7
+ const { i18n: userI18n, ...userConfigStripped } = userConfig;
8
+ const { i18n: defaultI18n, ...defaultConfigStripped } = defaultConfig;
9
+ const combinedConfig = {
10
+ ...defaultConfigStripped,
11
+ ...userConfigStripped,
12
+ ...defaultI18n,
13
+ ...userI18n
14
+ };
15
+ const { defaultNS, lng, localeExtension, localePath, nonExplicitSupportedLngs } = combinedConfig;
16
+ const locales = combinedConfig.locales.filter((l) => l !== "default");
17
+ /**
18
+ * Skips translation file resolution while in cimode
19
+ * https://github.com/i18next/next-i18next/pull/851#discussion_r503113620
20
+ */
21
+ if (lng === "cimode") return combinedConfig;
22
+ if (typeof combinedConfig.fallbackLng === "undefined") {
23
+ combinedConfig.fallbackLng = combinedConfig.defaultLocale;
24
+ if (combinedConfig.fallbackLng === "default") [combinedConfig.fallbackLng] = locales;
25
+ }
26
+ const userPrefix = userConfig?.interpolation?.prefix;
27
+ const userSuffix = userConfig?.interpolation?.suffix;
28
+ const prefix = userPrefix ?? "{{";
29
+ const suffix = userSuffix ?? "}}";
30
+ if (typeof userConfig?.localeStructure !== "string" && (userPrefix || userSuffix)) combinedConfig.localeStructure = `${prefix}lng${suffix}/${prefix}ns${suffix}`;
31
+ const { fallbackLng, localeStructure } = combinedConfig;
32
+ if (nonExplicitSupportedLngs) {
33
+ const createFallbackObject = (acc, l) => {
34
+ const [locale] = l.split("-");
35
+ acc[l] = [locale];
36
+ return acc;
37
+ };
38
+ if (typeof fallbackLng === "string") combinedConfig.fallbackLng = combinedConfig.locales.filter((l) => l.includes("-")).reduce(createFallbackObject, { default: [fallbackLng] });
39
+ else if (Array.isArray(fallbackLng)) combinedConfig.fallbackLng = combinedConfig.locales.filter((l) => l.includes("-")).reduce(createFallbackObject, { default: fallbackLng });
40
+ else if (typeof fallbackLng === "object") combinedConfig.fallbackLng = Object.entries(combinedConfig.fallbackLng).reduce((acc, [l, f]) => {
41
+ acc[l] = l.includes("-") ? unique([l.split("-")[0], ...f]) : f;
42
+ return acc;
43
+ }, fallbackLng);
44
+ else if (typeof fallbackLng === "function") throw new Error("If nonExplicitSupportedLngs is true, no functions are allowed for fallbackLng");
45
+ }
46
+ const hasCustomBackend = userConfig?.use?.filter(Boolean).some((b) => b.type === "backend");
47
+ if (!process.browser && typeof window === "undefined") {
48
+ if (options.applyServerSideConfig) options.applyServerSideConfig(combinedConfig, userConfig);
49
+ } else {
50
+ if (!hasCustomBackend) {
51
+ if (typeof localePath === "string") combinedConfig.backend = {
52
+ addPath: `${localePath}/${localeStructure}.missing.${localeExtension}`,
53
+ loadPath: `${localePath}/${localeStructure}.${localeExtension}`
54
+ };
55
+ else if (typeof localePath === "function") combinedConfig.backend = {
56
+ addPath: (locale, namespace) => localePath(locale, namespace, true),
57
+ loadPath: (locale, namespace) => localePath(locale, namespace, false)
58
+ };
59
+ }
60
+ if (typeof combinedConfig.ns !== "string" && !Array.isArray(combinedConfig.ns)) combinedConfig.ns = [defaultNS];
61
+ }
62
+ deepMergeObjects.forEach((obj) => {
63
+ if (userConfig[obj]) combinedConfig[obj] = {
64
+ ...combinedConfig[obj],
65
+ ...userConfig[obj]
66
+ };
67
+ });
68
+ return combinedConfig;
69
+ };
70
+ //#endregion
71
+ export { createConfig };
72
+
73
+ //# sourceMappingURL=createConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createConfig.mjs","names":[],"sources":["../../../src/pagesRouter/config/createConfig.ts"],"sourcesContent":["import { defaultConfig } from './defaultConfig'\nimport { InternalConfig, UserConfig } from '../types'\nimport { unique } from '../utils'\nimport { FallbackLngObjList, Module } from 'i18next'\n\nconst deepMergeObjects = ['backend', 'detection'] as (keyof Pick<\n UserConfig,\n 'backend' | 'detection'\n>)[]\n\ntype CreateConfigOptions = {\n // Hook called only on the server side. Kept as an injected dependency so\n // `createConfig` itself never references Node built-ins (`fs`, `path`,\n // `module`) and stays safe to bundle for the browser. Wired up by\n // `serverSideTranslations`, which is server-only.\n applyServerSideConfig?: (\n combinedConfig: any,\n userConfig: UserConfig\n ) => void\n}\n\nexport const createConfig = (\n userConfig: UserConfig,\n options: CreateConfigOptions = {}\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 if (options.applyServerSideConfig) {\n options.applyServerSideConfig(combinedConfig, userConfig)\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;AAgBjD,MAAa,gBACX,YACA,UAA+B,EAAE,KACd;AACnB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,KAAK,CAAC,GAAG,OAAsB;AAC3D,OAAI,KAAK,EAAE,SAAS,IAAI,GACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,GAC/B;AACJ,UAAO;KACN,YAAkC;WAC5B,OAAO,gBAAgB,WAChC,OAAM,IAAI,MACR,gFACD;;CAIL,MAAM,mBAAmB,YAAY,KAAK,OAAO,QAAQ,CAAC,MACvD,MAAc,EAAE,SAAS,UAC3B;AACD,KAAI,CAAC,QAAQ,WAAW,OAAO,WAAW;MACpC,QAAQ,sBACV,SAAQ,sBAAsB,gBAAgB,WAAW;QAEtD;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"}
@@ -0,0 +1,27 @@
1
+ //#region src/pagesRouter/config/defaultConfig.d.ts
2
+ declare const defaultConfig: {
3
+ defaultNS: string;
4
+ errorStackTraceLimit: number;
5
+ i18n: {
6
+ defaultLocale: string;
7
+ locales: string[];
8
+ };
9
+ readonly initImmediate: boolean;
10
+ readonly initAsync: boolean;
11
+ interpolation: {
12
+ escapeValue: boolean;
13
+ };
14
+ load: string;
15
+ localeExtension: string;
16
+ localePath: string;
17
+ localeStructure: string;
18
+ react: {
19
+ useSuspense: boolean;
20
+ };
21
+ reloadOnPrerender: boolean;
22
+ serializeConfig: boolean;
23
+ use: never[];
24
+ };
25
+ //#endregion
26
+ export { defaultConfig };
27
+ //# sourceMappingURL=defaultConfig.d.mts.map
@@ -0,0 +1,27 @@
1
+ const defaultConfig = {
2
+ defaultNS: "common",
3
+ errorStackTraceLimit: 0,
4
+ i18n: {
5
+ defaultLocale: "en",
6
+ locales: ["en"]
7
+ },
8
+ get initImmediate() {
9
+ return typeof window !== "undefined";
10
+ },
11
+ get initAsync() {
12
+ return typeof window !== "undefined";
13
+ },
14
+ interpolation: { escapeValue: false },
15
+ load: "currentOnly",
16
+ localeExtension: "json",
17
+ localePath: "./public/locales",
18
+ localeStructure: "{{lng}}/{{ns}}",
19
+ react: { useSuspense: false },
20
+ reloadOnPrerender: false,
21
+ serializeConfig: true,
22
+ use: []
23
+ };
24
+ //#endregion
25
+ export { defaultConfig };
26
+
27
+ //# sourceMappingURL=defaultConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultConfig.mjs","names":[],"sources":["../../../src/pagesRouter/config/defaultConfig.ts"],"sourcesContent":["const DEFAULT_LOCALE = 'en'\nconst LOCALES = ['en']\nconst DEFAULT_NAMESPACE = 'common'\nconst LOCALE_PATH = './public/locales'\nconst LOCALE_STRUCTURE = '{{lng}}/{{ns}}'\nconst LOCALE_EXTENSION = 'json'\n\nexport const defaultConfig = {\n defaultNS: DEFAULT_NAMESPACE,\n errorStackTraceLimit: 0,\n i18n: {\n defaultLocale: DEFAULT_LOCALE,\n locales: LOCALES,\n },\n get initImmediate(): boolean { // i18next < 24\n return typeof window !== 'undefined'\n },\n get initAsync(): boolean {\n return typeof window !== 'undefined'\n },\n interpolation: {\n escapeValue: false,\n },\n load: 'currentOnly',\n localeExtension: LOCALE_EXTENSION,\n localePath: LOCALE_PATH,\n localeStructure: LOCALE_STRUCTURE,\n react: {\n useSuspense: false,\n },\n reloadOnPrerender: false,\n serializeConfig: true,\n use: [],\n}\n"],"mappings":"AAOA,MAAa,gBAAgB;CAC3B,WANwB;CAOxB,sBAAsB;CACtB,MAAM;EACJ,eAXmB;EAYnB,SAXY,CAAC,KAAK;EAYnB;CACD,IAAI,gBAAyB;AAC3B,SAAO,OAAO,WAAW;;CAE3B,IAAI,YAAqB;AACvB,SAAO,OAAO,WAAW;;CAE3B,eAAe,EACb,aAAa,OACd;CACD,MAAM;CACN,iBAnBuB;CAoBvB,YAtBkB;CAuBlB,iBAtBuB;CAuBvB,OAAO,EACL,aAAa,OACd;CACD,mBAAmB;CACnB,iBAAiB;CACjB,KAAK,EAAE;CACR"}
@@ -0,0 +1,78 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
+ const require_utils = require("../utils.cjs");
4
+ let fs = require("fs");
5
+ fs = require_runtime.__toESM(fs);
6
+ let path = require("path");
7
+ path = require_runtime.__toESM(path);
8
+ //#region src/pagesRouter/config/serverSideConfig.ts
9
+ const applyServerSideConfig = (combinedConfig, userConfig) => {
10
+ const { defaultNS, lng, localeExtension, localePath, localeStructure, fallbackLng } = combinedConfig;
11
+ const userPrefix = userConfig?.interpolation?.prefix;
12
+ const userSuffix = userConfig?.interpolation?.suffix;
13
+ const prefix = userPrefix ?? "{{";
14
+ const suffix = userSuffix ?? "}}";
15
+ combinedConfig.preload = combinedConfig.locales.filter((l) => l !== "default");
16
+ if (userConfig?.use?.filter(Boolean).some((b) => b.type === "backend")) return;
17
+ if (typeof defaultNS === "string" && typeof lng !== "undefined") {
18
+ if (typeof localePath === "string") {
19
+ const defaultFile = `/${localeStructure.replace(`${prefix}lng${suffix}`, lng).replace(`${prefix}ns${suffix}`, defaultNS)}.${localeExtension}`;
20
+ const defaultNSPath = path.default.join(localePath, defaultFile);
21
+ const defaultNSExists = fs.default.existsSync(defaultNSPath);
22
+ const defaultFallbackNSExists = require_utils.getFallbackForLng(lng, fallbackLng).some((f) => {
23
+ const fallbackFile = defaultFile.replace(lng, f);
24
+ return fs.default.existsSync(path.default.join(localePath, fallbackFile));
25
+ });
26
+ if (!defaultNSExists && !defaultFallbackNSExists && process.env.NODE_ENV !== "production") throw new Error(`Default namespace not found at ${defaultNSPath}`);
27
+ } else if (typeof localePath === "function") {
28
+ const defaultNSPath = localePath(lng, defaultNS, false);
29
+ const defaultNSExists = fs.default.existsSync(defaultNSPath);
30
+ const defaultFallbackNSExists = require_utils.getFallbackForLng(lng, fallbackLng).some((f) => {
31
+ const fallbackNSPath = localePath(f, defaultNS, false);
32
+ return fs.default.existsSync(fallbackNSPath);
33
+ });
34
+ if (!defaultNSExists && !defaultFallbackNSExists && process.env.NODE_ENV !== "production") throw new Error(`Default namespace not found at ${defaultNSPath}`);
35
+ }
36
+ }
37
+ if (typeof localePath === "string") combinedConfig.backend = {
38
+ addPath: path.default.resolve(process.cwd(), `${localePath}/${localeStructure}.missing.${localeExtension}`),
39
+ loadPath: path.default.resolve(process.cwd(), `${localePath}/${localeStructure}.${localeExtension}`)
40
+ };
41
+ else if (typeof localePath === "function") combinedConfig.backend = {
42
+ addPath: (locale, namespace) => localePath(locale, namespace, true),
43
+ loadPath: (locale, namespace) => localePath(locale, namespace, false)
44
+ };
45
+ else if (localePath) throw new Error(`Unsupported localePath type: ${typeof localePath}`);
46
+ if (!combinedConfig.ns && typeof lng !== "undefined") {
47
+ if (typeof localePath === "function") throw new Error("Must provide all namespaces in ns option if using a function as localePath");
48
+ const getNamespaces = (loc) => {
49
+ const getLocaleNamespaces = (p) => {
50
+ let ret = [];
51
+ if (!fs.default.existsSync(p)) return ret;
52
+ fs.default.readdirSync(p).forEach((file) => {
53
+ const joinedP = path.default.join(p, file);
54
+ if (fs.default.statSync(joinedP).isDirectory()) {
55
+ const subRet = getLocaleNamespaces(joinedP).map((n) => `${file}/${n}`);
56
+ ret = ret.concat(subRet);
57
+ return;
58
+ }
59
+ ret.push(file.replace(`.${localeExtension}`, ""));
60
+ });
61
+ return ret;
62
+ };
63
+ let namespacesByLocale;
64
+ const r = combinedConfig.resources;
65
+ if (!localePath && r) namespacesByLocale = loc.map((locale) => Object.keys(r[locale]));
66
+ else namespacesByLocale = loc.map((locale) => getLocaleNamespaces(path.default.resolve(process.cwd(), `${localePath}/${locale}`)));
67
+ const allNamespaces = [];
68
+ for (const localNamespaces of namespacesByLocale) allNamespaces.push(...localNamespaces);
69
+ return require_utils.unique(allNamespaces);
70
+ };
71
+ if (localeStructure.indexOf(`${prefix}lng${suffix}`) > localeStructure.indexOf(`${prefix}ns${suffix}`)) throw new Error("Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns");
72
+ combinedConfig.ns = getNamespaces(require_utils.unique([lng, ...require_utils.getFallbackForLng(lng, fallbackLng)]));
73
+ }
74
+ };
75
+ //#endregion
76
+ exports.applyServerSideConfig = applyServerSideConfig;
77
+
78
+ //# sourceMappingURL=serverSideConfig.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverSideConfig.cjs","names":["getFallbackForLng","unique"],"sources":["../../../src/pagesRouter/config/serverSideConfig.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nimport { InternalConfig, UserConfig } from '../types'\nimport { getFallbackForLng, unique } from '../utils'\nimport { Module } from 'i18next'\n\n// Server-only logic extracted from createConfig so that the bundler never\n// traces `fs`/`path` from the client side. createConfig invokes this via the\n// `applyServerSideConfig` hook, which is wired up only by callers that are\n// guaranteed to run on the server (e.g. serverSideTranslations).\nexport const applyServerSideConfig = (\n combinedConfig: any,\n userConfig: UserConfig\n): void => {\n const {\n defaultNS,\n lng,\n localeExtension,\n localePath,\n localeStructure,\n fallbackLng,\n } = combinedConfig\n\n const userPrefix = userConfig?.interpolation?.prefix\n const userSuffix = userConfig?.interpolation?.suffix\n const prefix = userPrefix ?? '{{'\n const suffix = userSuffix ?? '}}'\n\n const locales: string[] = combinedConfig.locales.filter(\n (l: string) => l !== 'default'\n )\n\n combinedConfig.preload = locales\n\n const hasCustomBackend = userConfig?.use?.filter(Boolean).some(\n (b: Module) => b.type === 'backend'\n )\n if (hasCustomBackend) return\n\n //\n // Validate defaultNS\n // https://github.com/i18next/next-i18next/issues/358\n //\n if (typeof defaultNS === 'string' && typeof lng !== 'undefined') {\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(lng, fallbackLng)\n const defaultFallbackNSExists = fallback.some(f => {\n const fallbackFile = defaultFile.replace(lng, f)\n return fs.existsSync(path.join(localePath, fallbackFile))\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(`Default namespace not found at ${defaultNSPath}`)\n }\n } else if (typeof localePath === 'function') {\n const defaultNSPath = localePath(lng, defaultNS, false)\n const defaultNSExists = fs.existsSync(defaultNSPath)\n const fallback = getFallbackForLng(lng, fallbackLng)\n const defaultFallbackNSExists = fallback.some(f => {\n const fallbackNSPath = localePath(f, defaultNS, false)\n return fs.existsSync(fallbackNSPath)\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(`Default namespace not found at ${defaultNSPath}`)\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(`Unsupported localePath type: ${typeof localePath}`)\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 = (loc: string[]): string[] => {\n const getLocaleNamespaces = (p: string): string[] => {\n let ret: string[] = []\n if (!fs.existsSync(p)) return ret\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: string[][]\n const r = combinedConfig.resources\n if (!localePath && r) {\n namespacesByLocale = loc.map(locale => Object.keys(r[locale]))\n } else {\n namespacesByLocale = loc.map(locale =>\n getLocaleNamespaces(\n path.resolve(process.cwd(), `${localePath}/${locale}`)\n )\n )\n }\n\n const allNamespaces: string[] = []\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([lng, ...getFallbackForLng(lng, fallbackLng)])\n ) as InternalConfig['ns']\n }\n}\n"],"mappings":";;;;;;;;AAWA,MAAa,yBACX,gBACA,eACS;CACT,MAAM,EACJ,WACA,KACA,iBACA,YACA,iBACA,gBACE;CAEJ,MAAM,aAAa,YAAY,eAAe;CAC9C,MAAM,aAAa,YAAY,eAAe;CAC9C,MAAM,SAAS,cAAc;CAC7B,MAAM,SAAS,cAAc;AAM7B,gBAAe,UAJW,eAAe,QAAQ,QAC9C,MAAc,M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OAAO,IAAI,SAAS,CAE/C,OAAM,IAAI,MACR,iHACD;AAGH,iBAAe,KAAK,cAClBA,cAAAA,OAAO,CAAC,KAAK,GAAGD,cAAAA,kBAAkB,KAAK,YAAY,CAAC,CAAC,CACtD"}
@@ -0,0 +1,7 @@
1
+ import { UserConfig } from "../types.cjs";
2
+
3
+ //#region src/pagesRouter/config/serverSideConfig.d.ts
4
+ declare const applyServerSideConfig: (combinedConfig: any, userConfig: UserConfig) => void;
5
+ //#endregion
6
+ export { applyServerSideConfig };
7
+ //# sourceMappingURL=serverSideConfig.d.cts.map
@@ -0,0 +1,7 @@
1
+ import { UserConfig } from "../types.mjs";
2
+
3
+ //#region src/pagesRouter/config/serverSideConfig.d.ts
4
+ declare const applyServerSideConfig: (combinedConfig: any, userConfig: UserConfig) => void;
5
+ //#endregion
6
+ export { applyServerSideConfig };
7
+ //# sourceMappingURL=serverSideConfig.d.mts.map
@@ -0,0 +1,74 @@
1
+ import { getFallbackForLng, unique } from "../utils.mjs";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ //#region src/pagesRouter/config/serverSideConfig.ts
5
+ const applyServerSideConfig = (combinedConfig, userConfig) => {
6
+ const { defaultNS, lng, localeExtension, localePath, localeStructure, fallbackLng } = combinedConfig;
7
+ const userPrefix = userConfig?.interpolation?.prefix;
8
+ const userSuffix = userConfig?.interpolation?.suffix;
9
+ const prefix = userPrefix ?? "{{";
10
+ const suffix = userSuffix ?? "}}";
11
+ combinedConfig.preload = combinedConfig.locales.filter((l) => l !== "default");
12
+ if (userConfig?.use?.filter(Boolean).some((b) => b.type === "backend")) return;
13
+ if (typeof defaultNS === "string" && typeof lng !== "undefined") {
14
+ if (typeof localePath === "string") {
15
+ const defaultFile = `/${localeStructure.replace(`${prefix}lng${suffix}`, lng).replace(`${prefix}ns${suffix}`, defaultNS)}.${localeExtension}`;
16
+ const defaultNSPath = path.join(localePath, defaultFile);
17
+ const defaultNSExists = fs.existsSync(defaultNSPath);
18
+ const defaultFallbackNSExists = getFallbackForLng(lng, fallbackLng).some((f) => {
19
+ const fallbackFile = defaultFile.replace(lng, f);
20
+ return fs.existsSync(path.join(localePath, fallbackFile));
21
+ });
22
+ if (!defaultNSExists && !defaultFallbackNSExists && process.env.NODE_ENV !== "production") throw new Error(`Default namespace not found at ${defaultNSPath}`);
23
+ } else if (typeof localePath === "function") {
24
+ const defaultNSPath = localePath(lng, defaultNS, false);
25
+ const defaultNSExists = fs.existsSync(defaultNSPath);
26
+ const defaultFallbackNSExists = getFallbackForLng(lng, fallbackLng).some((f) => {
27
+ const fallbackNSPath = localePath(f, defaultNS, false);
28
+ return fs.existsSync(fallbackNSPath);
29
+ });
30
+ if (!defaultNSExists && !defaultFallbackNSExists && process.env.NODE_ENV !== "production") throw new Error(`Default namespace not found at ${defaultNSPath}`);
31
+ }
32
+ }
33
+ if (typeof localePath === "string") combinedConfig.backend = {
34
+ addPath: path.resolve(process.cwd(), `${localePath}/${localeStructure}.missing.${localeExtension}`),
35
+ loadPath: path.resolve(process.cwd(), `${localePath}/${localeStructure}.${localeExtension}`)
36
+ };
37
+ else if (typeof localePath === "function") combinedConfig.backend = {
38
+ addPath: (locale, namespace) => localePath(locale, namespace, true),
39
+ loadPath: (locale, namespace) => localePath(locale, namespace, false)
40
+ };
41
+ else if (localePath) throw new Error(`Unsupported localePath type: ${typeof localePath}`);
42
+ if (!combinedConfig.ns && typeof lng !== "undefined") {
43
+ if (typeof localePath === "function") throw new Error("Must provide all namespaces in ns option if using a function as localePath");
44
+ const getNamespaces = (loc) => {
45
+ const getLocaleNamespaces = (p) => {
46
+ let ret = [];
47
+ if (!fs.existsSync(p)) return ret;
48
+ fs.readdirSync(p).forEach((file) => {
49
+ const joinedP = path.join(p, file);
50
+ if (fs.statSync(joinedP).isDirectory()) {
51
+ const subRet = getLocaleNamespaces(joinedP).map((n) => `${file}/${n}`);
52
+ ret = ret.concat(subRet);
53
+ return;
54
+ }
55
+ ret.push(file.replace(`.${localeExtension}`, ""));
56
+ });
57
+ return ret;
58
+ };
59
+ let namespacesByLocale;
60
+ const r = combinedConfig.resources;
61
+ if (!localePath && r) namespacesByLocale = loc.map((locale) => Object.keys(r[locale]));
62
+ else namespacesByLocale = loc.map((locale) => getLocaleNamespaces(path.resolve(process.cwd(), `${localePath}/${locale}`)));
63
+ const allNamespaces = [];
64
+ for (const localNamespaces of namespacesByLocale) allNamespaces.push(...localNamespaces);
65
+ return unique(allNamespaces);
66
+ };
67
+ if (localeStructure.indexOf(`${prefix}lng${suffix}`) > localeStructure.indexOf(`${prefix}ns${suffix}`)) throw new Error("Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns");
68
+ combinedConfig.ns = getNamespaces(unique([lng, ...getFallbackForLng(lng, fallbackLng)]));
69
+ }
70
+ };
71
+ //#endregion
72
+ export { applyServerSideConfig };
73
+
74
+ //# sourceMappingURL=serverSideConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverSideConfig.mjs","names":[],"sources":["../../../src/pagesRouter/config/serverSideConfig.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nimport { InternalConfig, UserConfig } from '../types'\nimport { getFallbackForLng, unique } from '../utils'\nimport { Module } from 'i18next'\n\n// Server-only logic extracted from createConfig so that the bundler never\n// traces `fs`/`path` from the client side. createConfig invokes this via the\n// `applyServerSideConfig` hook, which is wired up only by callers that are\n// guaranteed to run on the server (e.g. serverSideTranslations).\nexport const applyServerSideConfig = (\n combinedConfig: any,\n userConfig: UserConfig\n): void => {\n const {\n defaultNS,\n lng,\n localeExtension,\n localePath,\n localeStructure,\n fallbackLng,\n } = combinedConfig\n\n const userPrefix = userConfig?.interpolation?.prefix\n const userSuffix = userConfig?.interpolation?.suffix\n const prefix = userPrefix ?? '{{'\n const suffix = userSuffix ?? '}}'\n\n const locales: string[] = combinedConfig.locales.filter(\n (l: string) => l !== 'default'\n )\n\n combinedConfig.preload = locales\n\n const hasCustomBackend = userConfig?.use?.filter(Boolean).some(\n (b: Module) => b.type === 'backend'\n )\n if (hasCustomBackend) return\n\n //\n // Validate defaultNS\n // https://github.com/i18next/next-i18next/issues/358\n //\n if (typeof defaultNS === 'string' && typeof lng !== 'undefined') {\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(lng, fallbackLng)\n const defaultFallbackNSExists = fallback.some(f => {\n const fallbackFile = defaultFile.replace(lng, f)\n return fs.existsSync(path.join(localePath, fallbackFile))\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(`Default namespace not found at ${defaultNSPath}`)\n }\n } else if (typeof localePath === 'function') {\n const defaultNSPath = localePath(lng, defaultNS, false)\n const defaultNSExists = fs.existsSync(defaultNSPath)\n const fallback = getFallbackForLng(lng, fallbackLng)\n const defaultFallbackNSExists = fallback.some(f => {\n const fallbackNSPath = localePath(f, defaultNS, false)\n return fs.existsSync(fallbackNSPath)\n })\n if (\n !defaultNSExists &&\n !defaultFallbackNSExists &&\n process.env.NODE_ENV !== 'production'\n ) {\n throw new Error(`Default namespace not found at ${defaultNSPath}`)\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(`Unsupported localePath type: ${typeof localePath}`)\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 = (loc: string[]): string[] => {\n const getLocaleNamespaces = (p: string): string[] => {\n let ret: string[] = []\n if (!fs.existsSync(p)) return ret\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: string[][]\n const r = combinedConfig.resources\n if (!localePath && r) {\n namespacesByLocale = loc.map(locale => Object.keys(r[locale]))\n } else {\n namespacesByLocale = loc.map(locale =>\n getLocaleNamespaces(\n path.resolve(process.cwd(), `${localePath}/${locale}`)\n )\n )\n }\n\n const allNamespaces: string[] = []\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([lng, ...getFallbackForLng(lng, fallbackLng)])\n ) as InternalConfig['ns']\n }\n}\n"],"mappings":";;;;AAWA,MAAa,yBACX,gBACA,eACS;CACT,MAAM,EACJ,WACA,KACA,iBACA,YACA,iBACA,gBACE;CAEJ,MAAM,aAAa,YAAY,eAAe;CAC9C,MAAM,aAAa,YAAY,eAAe;CAC9C,MAAM,SAAS,cAAc;CAC7B,MAAM,SAAS,cAAc;AAM7B,gBAAe,UAJW,eAAe,QAAQ,QAC9C,MAAc,MAAM,UACtB;AAOD,KAHyB,YAAY,KAAK,OAA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0,0 +1,7 @@
1
+ import { CreateClientReturn, InternalConfig } from "../types.mjs";
2
+
3
+ //#region src/pagesRouter/createClient/browser.d.ts
4
+ declare const _default: (config: InternalConfig) => CreateClientReturn;
5
+ //#endregion
6
+ export { _default as default };
7
+ //# sourceMappingURL=browser.d.mts.map
@@ -0,0 +1,20 @@
1
+ import i18n$1 from "i18next";
2
+ //#region src/pagesRouter/createClient/browser.ts
3
+ var browser_default = (config) => {
4
+ if (config.ns === void 0) config.ns = [];
5
+ const instance = i18n$1.createInstance(config);
6
+ let initPromise;
7
+ if (!instance.isInitialized) {
8
+ config?.use?.filter(Boolean).forEach((x) => instance.use(x));
9
+ if (typeof config.onPreInitI18next === "function") config.onPreInitI18next(instance);
10
+ initPromise = instance.init(config);
11
+ } else initPromise = Promise.resolve(i18n$1.t);
12
+ return {
13
+ i18n: instance,
14
+ initPromise
15
+ };
16
+ };
17
+ //#endregion
18
+ export { browser_default as default };
19
+
20
+ //# sourceMappingURL=browser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.mjs","names":["i18n"],"sources":["../../../src/pagesRouter/createClient/browser.ts"],"sourcesContent":["import i18n, { Module } from 'i18next'\n\nimport {\n InternalConfig,\n CreateClientReturn,\n InitPromise,\n I18n,\n} from '../types'\n\nexport default (config: InternalConfig): CreateClientReturn => {\n if (config.ns === undefined) config.ns = []\n const instance = i18n.createInstance(config) as I18n\n let initPromise: InitPromise\n\n if (!instance.isInitialized) {\n config?.use?.filter(Boolean).forEach((x: Module) => instance.use(x))\n if (typeof config.onPreInitI18next === 'function') {\n config.onPreInitI18next(instance)\n }\n initPromise = instance.init(config)\n } else {\n initPromise = Promise.resolve(i18n.t)\n }\n\n return { i18n: instance, initPromise }\n}\n"],"mappings":";;AASA,IAAA,mBAAgB,WAA+C;AAC7D,KAAI,OAAO,OAAO,KAAA,EAAW,QAAO,KAAK,EAAE;CAC3C,MAAM,WAAWA,OAAK,eAAe,OAAO;CAC5C,IAAI;AAEJ,KAAI,CAAC,SAAS,eAAe;AAC3B,UAAQ,KAAK,OAAO,QAAQ,CAAC,SAAS,MAAc,SAAS,IAAI,EAAE,CAAC;AACpE,MAAI,OAAO,OAAO,qBAAqB,WACrC,QAAO,iBAAiB,SAAS;AAEnC,gBAAc,SAAS,KAAK,OAAO;OAEnC,eAAc,QAAQ,QAAQA,OAAK,EAAE;AAGvC,QAAO;EAAE,MAAM;EAAU;EAAa"}
@@ -1,8 +1,8 @@
1
1
  const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
- let fs = require("fs");
3
- fs = require_runtime.__toESM(fs);
4
2
  let i18next = require("i18next");
5
3
  i18next = require_runtime.__toESM(i18next);
4
+ let fs = require("fs");
5
+ fs = require_runtime.__toESM(fs);
6
6
  let i18next_resources_to_backend = require("i18next-resources-to-backend");
7
7
  i18next_resources_to_backend = require_runtime.__toESM(i18next_resources_to_backend);
8
8
  //#region src/pagesRouter/createClient/node.ts
@@ -0,0 +1,7 @@
1
+ import { CreateClientReturn, InternalConfig } from "../types.mjs";
2
+
3
+ //#region src/pagesRouter/createClient/node.d.ts
4
+ declare const _default: (config: InternalConfig) => CreateClientReturn;
5
+ //#endregion
6
+ export { _default as default };
7
+ //# sourceMappingURL=node.d.mts.map
@@ -0,0 +1,44 @@
1
+ import i18n$1 from "i18next";
2
+ import fs from "fs";
3
+ import resourcesToBackend from "i18next-resources-to-backend";
4
+ //#region src/pagesRouter/createClient/node.ts
5
+ function createFSBackend(config) {
6
+ return resourcesToBackend((lng, ns) => {
7
+ const backend = config.backend;
8
+ let filePath;
9
+ if (typeof backend?.loadPath === "function") filePath = backend.loadPath(lng, ns);
10
+ else if (typeof backend?.loadPath === "string") filePath = backend.loadPath.replace("{{lng}}", lng).replace("{{ns}}", ns);
11
+ else filePath = `./public/locales/${lng}/${ns}.json`;
12
+ const content = fs.readFileSync(filePath, "utf-8");
13
+ return JSON.parse(content);
14
+ });
15
+ }
16
+ let globalInstance;
17
+ var node_default = (config) => {
18
+ if (config.ns === void 0) config.ns = [];
19
+ let instance;
20
+ if (!globalInstance) {
21
+ globalInstance = i18n$1.createInstance(config);
22
+ instance = globalInstance;
23
+ } else instance = globalInstance.cloneInstance({
24
+ ...config,
25
+ initAsync: false,
26
+ initImmediate: false
27
+ });
28
+ let initPromise;
29
+ if (!instance.isInitialized) {
30
+ const plugins = config?.use?.filter(Boolean) ?? [];
31
+ if (!plugins.some((b) => b.type === "backend")) instance.use(createFSBackend(config));
32
+ plugins.forEach((x) => instance.use(x));
33
+ if (typeof config.onPreInitI18next === "function") config.onPreInitI18next(instance);
34
+ initPromise = instance.init(config);
35
+ } else initPromise = Promise.resolve(i18n$1.t);
36
+ return {
37
+ i18n: instance,
38
+ initPromise
39
+ };
40
+ };
41
+ //#endregion
42
+ export { node_default as default };
43
+
44
+ //# sourceMappingURL=node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.mjs","names":["i18n"],"sources":["../../../src/pagesRouter/createClient/node.ts"],"sourcesContent":["import i18n, { Module } from 'i18next'\nimport resourcesToBackend from 'i18next-resources-to-backend'\nimport fs from 'fs'\n\nimport {\n InternalConfig,\n CreateClientReturn,\n InitPromise,\n I18n,\n} from '../types'\n\nfunction createFSBackend(config: InternalConfig) {\n return resourcesToBackend((lng: string, ns: string) => {\n const backend = config.backend as Record<string, any> | undefined\n let filePath: string\n if (typeof backend?.loadPath === 'function') {\n filePath = backend.loadPath(lng, ns)\n } else if (typeof backend?.loadPath === 'string') {\n filePath = backend.loadPath\n .replace('{{lng}}', lng)\n .replace('{{ns}}', ns)\n } else {\n filePath = `./public/locales/${lng}/${ns}.json`\n }\n const content = fs.readFileSync(filePath, 'utf-8')\n return JSON.parse(content)\n })\n}\n\nlet globalInstance: I18n\n\nexport default (config: InternalConfig): CreateClientReturn => {\n if (config.ns === undefined) config.ns = []\n let instance: I18n\n if (!globalInstance) {\n globalInstance = i18n.createInstance(config) as I18n\n instance = globalInstance\n } else {\n instance = globalInstance.cloneInstance({\n ...config,\n\n // @ts-ignore\n initAsync: false,\n\n // @ts-ignore\n initImmediate: false, // i18next < 24\n }) as I18n\n }\n let initPromise: InitPromise\n\n if (!instance.isInitialized) {\n const plugins = config?.use?.filter(Boolean) ?? []\n const hasCustomBackend = plugins.some(\n (b: Module) => b.type === 'backend'\n )\n if (!hasCustomBackend) {\n instance.use(createFSBackend(config))\n }\n\n plugins.forEach((x: Module) => instance.use(x))\n if (typeof config.onPreInitI18next === 'function') {\n config.onPreInitI18next(instance)\n }\n initPromise = instance.init(config)\n } else {\n initPromise = Promise.resolve(i18n.t)\n }\n\n return { i18n: instance, initPromise }\n}\n"],"mappings":";;;;AAWA,SAAS,gBAAgB,QAAwB;AAC/C,QAAO,oBAAoB,KAAa,OAAe;EACrD,MAAM,UAAU,OAAO;EACvB,IAAI;AACJ,MAAI,OAAO,SAAS,aAAa,WAC/B,YAAW,QAAQ,SAAS,KAAK,GAAG;WAC3B,OAAO,SAAS,aAAa,SACtC,YAAW,QAAQ,SAChB,QAAQ,WAAW,IAAI,CACvB,QAAQ,UAAU,GAAG;MAExB,YAAW,oBAAoB,IAAI,GAAG,GAAG;EAE3C,MAAM,UAAU,GAAG,aAAa,UAAU,QAAQ;AAClD,SAAO,KAAK,MAAM,QAAQ;GAC1B;;AAGJ,IAAI;AAEJ,IAAA,gBAAgB,WAA+C;AAC7D,KAAI,OAAO,OAAO,KAAA,EAAW,QAAO,KAAK,EAAE;CAC3C,IAAI;AACJ,KAAI,CAAC,gBAAgB;AACnB,mBAAiBA,OAAK,eAAe,OAAO;AAC5C,aAAW;OAEX,YAAW,eAAe,cAAc;EACtC,GAAG;EAGH,WAAW;EAGX,eAAe;EAChB,CAAC;CAEJ,IAAI;AAEJ,KAAI,CAAC,SAAS,eAAe;EAC3B,MAAM,UAAU,QAAQ,KAAK,OAAO,QAAQ,IAAI,EAAE;AAIlD,MAAI,CAHqB,QAAQ,MAC9B,MAAc,EAAE,SAAS,UAC3B,CAEC,UAAS,IAAI,gBAAgB,OAAO,CAAC;AAGvC,UAAQ,SAAS,MAAc,SAAS,IAAI,EAAE,CAAC;AAC/C,MAAI,OAAO,OAAO,qBAAqB,WACrC,QAAO,iBAAiB,SAAS;AAEnC,gBAAc,SAAS,KAAK,OAAO;OAEnC,eAAc,QAAQ,QAAQA,OAAK,EAAE;AAGvC,QAAO;EAAE,MAAM;EAAU;EAAa"}
@@ -0,0 +1,4 @@
1
+ import { I18n, SSRConfig, TFunction, UseTranslation, UserConfig, WithTranslation, WithTranslationHocType } from "./types.mjs";
2
+ import { appWithTranslation, globalI18n } from "./appWithTranslation.mjs";
3
+ import { I18nContext, Trans, Translation, useTranslation, withTranslation } from "react-i18next";
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 };
@@ -0,0 +1,3 @@
1
+ import { appWithTranslation, globalI18n } from "./appWithTranslation.mjs";
2
+ import { I18nContext, Trans, Translation, useTranslation, withTranslation } from "react-i18next";
3
+ export { I18nContext, Trans, Translation, appWithTranslation, globalI18n as i18n, useTranslation, withTranslation };
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
3
3
  const require_utils = require("./utils.cjs");
4
4
  const require_config_createConfig = require("./config/createConfig.cjs");
5
+ const require_config_serverSideConfig = require("./config/serverSideConfig.cjs");
5
6
  const require_createClient_node = require("./createClient/node.cjs");
6
7
  let fs = require("fs");
7
8
  fs = require_runtime.__toESM(fs);
@@ -21,12 +22,12 @@ const serverSideTranslations = async (initialLocale, namespacesRequired = void 0
21
22
  if (typeof initialLocale !== "string") throw new Error("Initial locale argument was not passed into serverSideTranslations");
22
23
  let userConfig = configOverride;
23
24
  const configPath = path.default.resolve(DEFAULT_CONFIG_PATH);
24
- if (!userConfig && fs.default.existsSync(configPath)) userConfig = (0, module$1.createRequire)(__filename)(configPath);
25
+ if (!userConfig && fs.default.existsSync(configPath)) userConfig = (0, module$1.createRequire)(configPath)(configPath);
25
26
  if (userConfig === null) throw new Error(`next-i18next was unable to find a user config at ${configPath}`);
26
27
  const config = require_config_createConfig.createConfig({
27
28
  ...userConfig,
28
29
  lng: initialLocale
29
- });
30
+ }, { applyServerSideConfig: require_config_serverSideConfig.applyServerSideConfig });
30
31
  const { localeExtension, localePath, fallbackLng, reloadOnPrerender } = config;
31
32
  const { i18n, initPromise } = require_createClient_node({
32
33
  ...config,
@@ -1 +1 @@
1
- {"version":3,"file":"serverSideTranslations.cjs","names":["createConfig","createClient","path","unique"],"sources":["../../src/pagesRouter/serverSideTranslations.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { createRequire } from 'module'\n\nimport { createConfig } from './config/createConfig'\nimport createClient from './createClient/node'\n\nimport { UserConfig, SSRConfig } from './types'\nimport { getFallbackForLng, unique } from './utils'\nimport { Module, Namespace } from 'i18next'\n\nlet DEFAULT_CONFIG_PATH = './next-i18next.config.js'\n\n/**\n * One line expression like `const { I18NEXT_DEFAULT_CONFIG_PATH: DEFAULT_CONFIG_PATH = './next-i18next.config.js' } = process.env;`\n * is breaking the build, so keep it like this.\n *\n * @see https://github.com/i18next/next-i18next/pull/2084#issuecomment-1420511358\n */\nif (process.env.I18NEXT_DEFAULT_CONFIG_PATH) {\n DEFAULT_CONFIG_PATH = process.env.I18NEXT_DEFAULT_CONFIG_PATH\n}\n\ntype ArrayElementOrSelf<T> = T extends ReadonlyArray<infer U> ? U[] : T[]\n\nexport const serverSideTranslations = async (\n initialLocale: string,\n namespacesRequired:\n | ArrayElementOrSelf<Namespace>\n | string\n | string[]\n | undefined = undefined,\n configOverride: UserConfig | null = null,\n extraLocales: string[] | false = false\n): Promise<SSRConfig> => {\n if (typeof initialLocale !== 'string') {\n throw new Error(\n 'Initial locale argument was not passed into serverSideTranslations'\n )\n }\n\n let userConfig = configOverride\n const configPath = path.resolve(DEFAULT_CONFIG_PATH)\n\n if (!userConfig && fs.existsSync(configPath)) {\n // Use createRequire to prevent Turbopack/webpack from tracing this dynamic require\n const nodeRequire = createRequire(__filename)\n userConfig = nodeRequire(configPath)\n }\n\n if (userConfig === null) {\n throw new Error(\n `next-i18next was unable to find a user config at ${configPath}`\n )\n }\n\n const config = createConfig({\n ...userConfig,\n lng: initialLocale,\n })\n\n const {\n localeExtension,\n localePath,\n fallbackLng,\n reloadOnPrerender,\n } = config\n\n const { i18n, initPromise } = createClient({\n ...config,\n lng: initialLocale,\n })\n\n await initPromise\n\n const hasCustomBackend = userConfig?.use?.filter(Boolean).some(\n (b: Module) => b.type === 'backend'\n )\n if (hasCustomBackend && namespacesRequired) {\n await i18n.loadNamespaces(Array.isArray(namespacesRequired) ? (namespacesRequired as string[]) : (namespacesRequired as string))\n }\n\n const initialI18nStore: Record<string, any> = {\n [initialLocale]: {},\n }\n\n getFallbackForLng(initialLocale, fallbackLng ?? false)\n .concat(extraLocales || [])\n .forEach((lng: string) => {\n initialI18nStore[lng] = {}\n })\n\n if (!Array.isArray(namespacesRequired)) {\n if (typeof localePath === 'function') {\n throw new Error(\n 'Must provide namespacesRequired to serverSideTranslations when using a function as localePath'\n )\n }\n\n const getLocaleNamespaces = (path: string) =>\n fs.existsSync(path)\n ? fs\n .readdirSync(path)\n .map(file => file.replace(`.${localeExtension}`, ''))\n : []\n\n const namespacesByLocale = Object.keys(initialI18nStore)\n .map(locale =>\n getLocaleNamespaces(\n path.resolve(process.cwd(), `${localePath}/${locale}`)\n )\n )\n .flat()\n\n namespacesRequired = unique(namespacesByLocale)\n }\n\n // Dev-only hot-reload: every backend (resources-to-backend, http, locize,\n // chained) refetches unconditionally with no dedup, so doing this in\n // production would hammer the source on every prerender call. Scope to\n // exactly the locales × namespaces this call will ship.\n if (reloadOnPrerender && process.env.NODE_ENV !== 'production') {\n await i18n.reloadResources(\n Object.keys(initialI18nStore),\n namespacesRequired as string[]\n )\n }\n\n namespacesRequired.forEach(ns => {\n for (const locale in initialI18nStore) {\n initialI18nStore[locale][ns] =\n (i18n.services.resourceStore.data[locale] || {})[ns] || {}\n }\n })\n\n return {\n _nextI18Next: {\n initialI18nStore,\n initialLocale,\n ns: namespacesRequired,\n userConfig: config.serializeConfig ? userConfig : null,\n },\n }\n}\n"],"mappings":";;;;;;;;;;;AAWA,IAAI,sBAAsB;;;;;;;AAQ1B,IAAI,QAAQ,IAAI,4BACd,uBAAsB,QAAQ,IAAI;AAKpC,MAAa,yBAAyB,OACpC,eACA,qBAIgB,KAAA,GAChB,iBAAoC,MACpC,eAAiC,UACV;AACvB,KAAI,OAAO,kBAAkB,SAC3B,OAAM,IAAI,MACR,qEACD;CAGH,IAAI,aAAa;CACjB,MAAM,aAAa,KAAA,QAAK,QAAQ,oBAAoB;AAEpD,KAAI,CAAC,cAAc,GAAA,QAAG,WAAW,WAAW,CAG1C,eAAA,GAAA,SAAA,eADkC,WAAW,CACpB,WAAW;AAGtC,KAAI,eAAe,KACjB,OAAM,IAAI,MACR,oDAAoD,aACrD;CAGH,MAAM,SAASA,4BAAAA,aAAa;EAC1B,GAAG;EACH,KAAK;EACN,CAAC;CAEF,MAAM,EACJ,iBACA,YACA,aACA,sBACE;CAEJ,MAAM,EAAE,MAAM,gBAAgBC,0BAAa;EACzC,GAAG;EACH,KAAK;EACN,CAAC;AAEF,OAAM;AAKN,KAHyB,YAAY,KAAK,OAAO,QAAQ,CAAC,MACvD,MAAc,EAAE,SAAS,UAC3B,IACuB,mBACtB,OAAM,KAAK,eAAe,MAAM,QAAQ,mBAAmB,GAAI,qBAAmC,mBAA8B;CAGlI,MAAM,mBAAwC,GAC3C,gBAAgB,EAAE,EACpB;AAED,eAAA,kBAAkB,eAAe,eAAe,MAAM,CACnD,OAAO,gBAAgB,EAAE,CAAC,CAC1B,SAAS,QAAgB;AACxB,mBAAiB,OAAO,EAAE;GAC1B;AAEJ,KAAI,CAAC,MAAM,QAAQ,mBAAmB,EAAE;AACtC,MAAI,OAAO,eAAe,WACxB,OAAM,IAAI,MACR,gGACD;EAGH,MAAM,uBAAuB,WAC3B,GAAA,QAAG,WAAWC,OAAK,GACf,GAAA,QACC,YAAYA,OAAK,CACjB,KAAI,SAAQ,KAAK,QAAQ,IAAI,mBAAmB,GAAG,CAAC,GACrD,EAAE;AAUR,uBAAqBC,cAAAA,OARM,OAAO,KAAK,iBAAiB,CACrD,KAAI,WACH,oBACE,KAAA,QAAK,QAAQ,QAAQ,KAAK,EAAE,GAAG,WAAW,GAAG,SAAS,CACvD,CACF,CACA,MAAM,CAEsC;;AAOjD,KAAI,qBAAqB,QAAQ,IAAI,aAAa,aAChD,OAAM,KAAK,gBACT,OAAO,KAAK,iBAAiB,EAC7B,mBACD;AAGH,oBAAmB,SAAQ,OAAM;AAC/B,OAAK,MAAM,UAAU,iBACnB,kBAAiB,QAAQ,OACtB,KAAK,SAAS,cAAc,KAAK,WAAW,EAAE,EAAE,OAAO,EAAE;GAE9D;AAEF,QAAO,EACL,cAAc;EACZ;EACA;EACA,IAAI;EACJ,YAAY,OAAO,kBAAkB,aAAa;EACnD,EACF"}
1
+ {"version":3,"file":"serverSideTranslations.cjs","names":["createConfig","createClient","path","unique"],"sources":["../../src/pagesRouter/serverSideTranslations.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { createRequire } from 'module'\n\nimport { createConfig } from './config/createConfig'\nimport { applyServerSideConfig } from './config/serverSideConfig'\nimport createClient from './createClient/node'\n\nimport { UserConfig, SSRConfig } from './types'\nimport { getFallbackForLng, unique } from './utils'\nimport { Module, Namespace } from 'i18next'\n\nlet DEFAULT_CONFIG_PATH = './next-i18next.config.js'\n\n/**\n * One line expression like `const { I18NEXT_DEFAULT_CONFIG_PATH: DEFAULT_CONFIG_PATH = './next-i18next.config.js' } = process.env;`\n * is breaking the build, so keep it like this.\n *\n * @see https://github.com/i18next/next-i18next/pull/2084#issuecomment-1420511358\n */\nif (process.env.I18NEXT_DEFAULT_CONFIG_PATH) {\n DEFAULT_CONFIG_PATH = process.env.I18NEXT_DEFAULT_CONFIG_PATH\n}\n\ntype ArrayElementOrSelf<T> = T extends ReadonlyArray<infer U> ? U[] : T[]\n\nexport const serverSideTranslations = async (\n initialLocale: string,\n namespacesRequired:\n | ArrayElementOrSelf<Namespace>\n | string\n | string[]\n | undefined = undefined,\n configOverride: UserConfig | null = null,\n extraLocales: string[] | false = false\n): Promise<SSRConfig> => {\n if (typeof initialLocale !== 'string') {\n throw new Error(\n 'Initial locale argument was not passed into serverSideTranslations'\n )\n }\n\n let userConfig = configOverride\n const configPath = path.resolve(DEFAULT_CONFIG_PATH)\n\n if (!userConfig && fs.existsSync(configPath)) {\n // Use createRequire to prevent Turbopack/webpack from tracing this dynamic require.\n // Pass the absolute configPath itself as the base — works identically under CJS\n // and ESM output and avoids referencing __filename / import.meta.url.\n const nodeRequire = createRequire(configPath)\n userConfig = nodeRequire(configPath)\n }\n\n if (userConfig === null) {\n throw new Error(\n `next-i18next was unable to find a user config at ${configPath}`\n )\n }\n\n const config = createConfig(\n {\n ...userConfig,\n lng: initialLocale,\n },\n { applyServerSideConfig }\n )\n\n const {\n localeExtension,\n localePath,\n fallbackLng,\n reloadOnPrerender,\n } = config\n\n const { i18n, initPromise } = createClient({\n ...config,\n lng: initialLocale,\n })\n\n await initPromise\n\n const hasCustomBackend = userConfig?.use?.filter(Boolean).some(\n (b: Module) => b.type === 'backend'\n )\n if (hasCustomBackend && namespacesRequired) {\n await i18n.loadNamespaces(Array.isArray(namespacesRequired) ? (namespacesRequired as string[]) : (namespacesRequired as string))\n }\n\n const initialI18nStore: Record<string, any> = {\n [initialLocale]: {},\n }\n\n getFallbackForLng(initialLocale, fallbackLng ?? false)\n .concat(extraLocales || [])\n .forEach((lng: string) => {\n initialI18nStore[lng] = {}\n })\n\n if (!Array.isArray(namespacesRequired)) {\n if (typeof localePath === 'function') {\n throw new Error(\n 'Must provide namespacesRequired to serverSideTranslations when using a function as localePath'\n )\n }\n\n const getLocaleNamespaces = (path: string) =>\n fs.existsSync(path)\n ? fs\n .readdirSync(path)\n .map(file => file.replace(`.${localeExtension}`, ''))\n : []\n\n const namespacesByLocale = Object.keys(initialI18nStore)\n .map(locale =>\n getLocaleNamespaces(\n path.resolve(process.cwd(), `${localePath}/${locale}`)\n )\n )\n .flat()\n\n namespacesRequired = unique(namespacesByLocale)\n }\n\n // Dev-only hot-reload: every backend (resources-to-backend, http, locize,\n // chained) refetches unconditionally with no dedup, so doing this in\n // production would hammer the source on every prerender call. Scope to\n // exactly the locales × namespaces this call will ship.\n if (reloadOnPrerender && process.env.NODE_ENV !== 'production') {\n await i18n.reloadResources(\n Object.keys(initialI18nStore),\n namespacesRequired as string[]\n )\n }\n\n namespacesRequired.forEach(ns => {\n for (const locale in initialI18nStore) {\n initialI18nStore[locale][ns] =\n (i18n.services.resourceStore.data[locale] || {})[ns] || {}\n }\n })\n\n return {\n _nextI18Next: {\n initialI18nStore,\n initialLocale,\n ns: namespacesRequired,\n userConfig: config.serializeConfig ? userConfig : null,\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAI,sBAAsB;;;;;;;AAQ1B,IAAI,QAAQ,IAAI,4BACd,uBAAsB,QAAQ,IAAI;AAKpC,MAAa,yBAAyB,OACpC,eACA,qBAIgB,KAAA,GAChB,iBAAoC,MACpC,eAAiC,UACV;AACvB,KAAI,OAAO,kBAAkB,SAC3B,OAAM,IAAI,MACR,qEACD;CAGH,IAAI,aAAa;CACjB,MAAM,aAAa,KAAA,QAAK,QAAQ,oBAAoB;AAEpD,KAAI,CAAC,cAAc,GAAA,QAAG,WAAW,WAAW,CAK1C,eAAA,GAAA,SAAA,eADkC,WAAW,CACpB,WAAW;AAGtC,KAAI,eAAe,KACjB,OAAM,IAAI,MACR,oDAAoD,aACrD;CAGH,MAAM,SAASA,4BAAAA,aACb;EACE,GAAG;EACH,KAAK;EACN,EACD,EAAE,uBAAA,gCAAA,uBAAuB,CAC1B;CAED,MAAM,EACJ,iBACA,YACA,aACA,sBAC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"i18next";
3
+
4
+ //#region src/pagesRouter/serverSideTranslations.d.ts
5
+ type ArrayElementOrSelf<T> = T extends ReadonlyArray<infer U> ? U[] : T[];
6
+ declare const serverSideTranslations: (initialLocale: string, namespacesRequired?: ArrayElementOrSelf<Namespace> | string | string[] | undefined, configOverride?: UserConfig | null, extraLocales?: string[] | false) => Promise<SSRConfig>;
7
+ //#endregion
8
+ export { serverSideTranslations };
9
+ //# sourceMappingURL=serverSideTranslations.d.mts.map
@@ -0,0 +1,57 @@
1
+ import { getFallbackForLng, unique } from "./utils.mjs";
2
+ import { createConfig } from "./config/createConfig.mjs";
3
+ import { applyServerSideConfig } from "./config/serverSideConfig.mjs";
4
+ import node_default from "./createClient/node.mjs";
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import { createRequire } from "module";
8
+ //#region src/pagesRouter/serverSideTranslations.ts
9
+ let DEFAULT_CONFIG_PATH = "./next-i18next.config.js";
10
+ /**
11
+ * One line expression like `const { I18NEXT_DEFAULT_CONFIG_PATH: DEFAULT_CONFIG_PATH = './next-i18next.config.js' } = process.env;`
12
+ * is breaking the build, so keep it like this.
13
+ *
14
+ * @see https://github.com/i18next/next-i18next/pull/2084#issuecomment-1420511358
15
+ */
16
+ if (process.env.I18NEXT_DEFAULT_CONFIG_PATH) DEFAULT_CONFIG_PATH = process.env.I18NEXT_DEFAULT_CONFIG_PATH;
17
+ const serverSideTranslations = async (initialLocale, namespacesRequired = void 0, configOverride = null, extraLocales = false) => {
18
+ if (typeof initialLocale !== "string") throw new Error("Initial locale argument was not passed into serverSideTranslations");
19
+ let userConfig = configOverride;
20
+ const configPath = path.resolve(DEFAULT_CONFIG_PATH);
21
+ if (!userConfig && fs.existsSync(configPath)) userConfig = createRequire(configPath)(configPath);
22
+ if (userConfig === null) throw new Error(`next-i18next was unable to find a user config at ${configPath}`);
23
+ const config = createConfig({
24
+ ...userConfig,
25
+ lng: initialLocale
26
+ }, { applyServerSideConfig });
27
+ const { localeExtension, localePath, fallbackLng, reloadOnPrerender } = config;
28
+ const { i18n, initPromise } = node_default({
29
+ ...config,
30
+ lng: initialLocale
31
+ });
32
+ await initPromise;
33
+ if (userConfig?.use?.filter(Boolean).some((b) => b.type === "backend") && namespacesRequired) await i18n.loadNamespaces(Array.isArray(namespacesRequired) ? namespacesRequired : namespacesRequired);
34
+ const initialI18nStore = { [initialLocale]: {} };
35
+ getFallbackForLng(initialLocale, fallbackLng ?? false).concat(extraLocales || []).forEach((lng) => {
36
+ initialI18nStore[lng] = {};
37
+ });
38
+ if (!Array.isArray(namespacesRequired)) {
39
+ if (typeof localePath === "function") throw new Error("Must provide namespacesRequired to serverSideTranslations when using a function as localePath");
40
+ const getLocaleNamespaces = (path) => fs.existsSync(path) ? fs.readdirSync(path).map((file) => file.replace(`.${localeExtension}`, "")) : [];
41
+ namespacesRequired = unique(Object.keys(initialI18nStore).map((locale) => getLocaleNamespaces(path.resolve(process.cwd(), `${localePath}/${locale}`))).flat());
42
+ }
43
+ if (reloadOnPrerender && process.env.NODE_ENV !== "production") await i18n.reloadResources(Object.keys(initialI18nStore), namespacesRequired);
44
+ namespacesRequired.forEach((ns) => {
45
+ for (const locale in initialI18nStore) initialI18nStore[locale][ns] = (i18n.services.resourceStore.data[locale] || {})[ns] || {};
46
+ });
47
+ return { _nextI18Next: {
48
+ initialI18nStore,
49
+ initialLocale,
50
+ ns: namespacesRequired,
51
+ userConfig: config.serializeConfig ? userConfig : null
52
+ } };
53
+ };
54
+ //#endregion
55
+ export { serverSideTranslations };
56
+
57
+ //# sourceMappingURL=serverSideTranslations.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverSideTranslations.mjs","names":["createClient"],"sources":["../../src/pagesRouter/serverSideTranslations.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { createRequire } from 'module'\n\nimport { createConfig } from './config/createConfig'\nimport { applyServerSideConfig } from './config/serverSideConfig'\nimport createClient from './createClient/node'\n\nimport { UserConfig, SSRConfig } from './types'\nimport { getFallbackForLng, unique } from './utils'\nimport { Module, Namespace } from 'i18next'\n\nlet DEFAULT_CONFIG_PATH = './next-i18next.config.js'\n\n/**\n * One line expression like `const { I18NEXT_DEFAULT_CONFIG_PATH: DEFAULT_CONFIG_PATH = './next-i18next.config.js' } = process.env;`\n * is breaking the build, so keep it like this.\n *\n * @see https://github.com/i18next/next-i18next/pull/2084#issuecomment-1420511358\n */\nif (process.env.I18NEXT_DEFAULT_CONFIG_PATH) {\n DEFAULT_CONFIG_PATH = process.env.I18NEXT_DEFAULT_CONFIG_PATH\n}\n\ntype ArrayElementOrSelf<T> = T extends ReadonlyArray<infer U> ? U[] : T[]\n\nexport const serverSideTranslations = async (\n initialLocale: string,\n namespacesRequired:\n | ArrayElementOrSelf<Namespace>\n | string\n | string[]\n | undefined = undefined,\n configOverride: UserConfig | null = null,\n extraLocales: string[] | false = false\n): Promise<SSRConfig> => {\n if (typeof initialLocale !== 'string') {\n throw new Error(\n 'Initial locale argument was not passed into serverSideTranslations'\n )\n }\n\n let userConfig = configOverride\n const configPath = path.resolve(DEFAULT_CONFIG_PATH)\n\n if (!userConfig && fs.existsSync(configPath)) {\n // Use createRequire to prevent Turbopack/webpack from tracing this dynamic require.\n // Pass the absolute configPath itself as the base — works identically under CJS\n // and ESM output and avoids referencing __filename / import.meta.url.\n const nodeRequire = createRequire(configPath)\n userConfig = nodeRequire(configPath)\n }\n\n if (userConfig === null) {\n throw new Error(\n `next-i18next was unable to find a user config at ${configPath}`\n )\n }\n\n const config = createConfig(\n {\n ...userConfig,\n lng: initialLocale,\n },\n { applyServerSideConfig }\n )\n\n const {\n localeExtension,\n localePath,\n fallbackLng,\n reloadOnPrerender,\n } = config\n\n const { i18n, initPromise } = createClient({\n ...config,\n lng: initialLocale,\n })\n\n await initPromise\n\n const hasCustomBackend = userConfig?.use?.filter(Boolean).some(\n (b: Module) => b.type === 'backend'\n )\n if (hasCustomBackend && namespacesRequired) {\n await i18n.loadNamespaces(Array.isArray(namespacesRequired) ? (namespacesRequired as string[]) : (namespacesRequired as string))\n }\n\n const initialI18nStore: Record<string, any> = {\n [initialLocale]: {},\n }\n\n getFallbackForLng(initialLocale, fallbackLng ?? false)\n .concat(extraLocales || [])\n .forEach((lng: string) => {\n initialI18nStore[lng] = {}\n })\n\n if (!Array.isArray(namespacesRequired)) {\n if (typeof localePath === 'function') {\n throw new Error(\n 'Must provide namespacesRequired to serverSideTranslations when using a function as localePath'\n )\n }\n\n const getLocaleNamespaces = (path: string) =>\n fs.existsSync(path)\n ? fs\n .readdirSync(path)\n .map(file => file.replace(`.${localeExtension}`, ''))\n : []\n\n const namespacesByLocale = Object.keys(initialI18nStore)\n .map(locale =>\n getLocaleNamespaces(\n path.resolve(process.cwd(), `${localePath}/${locale}`)\n )\n )\n .flat()\n\n namespacesRequired = unique(namespacesByLocale)\n }\n\n // Dev-only hot-reload: every backend (resources-to-backend, http, locize,\n // chained) refetches unconditionally with no dedup, so doing this in\n // production would hammer the source on every prerender call. Scope to\n // exactly the locales × namespaces this call will ship.\n if (reloadOnPrerender && process.env.NODE_ENV !== 'production') {\n await i18n.reloadResources(\n Object.keys(initialI18nStore),\n namespacesRequired as string[]\n )\n }\n\n namespacesRequired.forEach(ns => {\n for (const locale in initialI18nStore) {\n initialI18nStore[locale][ns] =\n (i18n.services.resourceStore.data[locale] || {})[ns] || {}\n }\n })\n\n return {\n _nextI18Next: {\n initialI18nStore,\n initialLocale,\n ns: namespacesRequired,\n userConfig: config.serializeConfig ? userConfig : null,\n },\n }\n}\n"],"mappings":";;;;;;;;AAYA,IAAI,sBAAsB;;;;;;;AAQ1B,IAAI,QAAQ,IAAI,4BACd,uBAAsB,QAAQ,IAAI;AAKpC,MAAa,yBAAyB,OACpC,eACA,qBAIgB,KAAA,GAChB,iBAAoC,MACpC,eAAiC,UACV;AACvB,KAAI,OAAO,kBAAkB,SAC3B,OAAM,IAAI,MACR,qEACD;CAGH,IAAI,aAAa;CACjB,MAAM,aAAa,KAAK,QAAQ,oBAAoB;A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AS,cAAc,KAAK,WAAW,EAAE,EAAE,OAAO,EAAE;GAE9D;AAEF,QAAO,EACL,cAAc;EACZ;EACA;EACA,IAAI;EACJ,YAAY,OAAO,kBAAkB,aAAa;EACnD,EACF"}
@@ -0,0 +1,59 @@
1
+ import { appWithTranslation, globalI18n } from "./appWithTranslation.mjs";
2
+ import { FallbackNs, I18nContext, Trans, Translation, UseTranslationOptions, UseTranslationResponse, WithTranslation as WithTranslation$1, useTranslation, withTranslation } from "react-i18next";
3
+ import { FlatNamespace, InitOptions, KeyPrefix, TFunction as TFunction$1, TypeOptions, i18n } from "i18next";
4
+
5
+ //#region src/pagesRouter/types.d.ts
6
+ /**
7
+ * Inlined from `import('next').NextConfig.i18n` v13.0.6. As we support
8
+ * multiple nextjs versions it's safer to inline and keep it up-to-date.
9
+ */
10
+ type NextJsI18NConfig = {
11
+ defaultLocale: string;
12
+ domains?: {
13
+ defaultLocale: string;
14
+ domain: string;
15
+ http?: true;
16
+ locales?: string[];
17
+ }[];
18
+ localeDetection?: false;
19
+ locales: string[];
20
+ };
21
+ type DefaultNamespace = TypeOptions['defaultNS'];
22
+ type UserConfig = {
23
+ i18n: NextJsI18NConfig;
24
+ localeExtension?: string;
25
+ localePath?: string | ((locale: string, namespace: string, missing: boolean) => string) | null;
26
+ localeStructure?: string;
27
+ onPreInitI18next?: (i18n: I18n) => void;
28
+ reloadOnPrerender?: boolean;
29
+ serializeConfig?: boolean;
30
+ use?: any[];
31
+ } & InitOptions;
32
+ type InternalConfig = Omit<UserConfig, 'i18n'> & NextJsI18NConfig & {
33
+ errorStackTraceLimit: number;
34
+ preload: string[];
35
+ supportedLngs: string[];
36
+ };
37
+ type $Tuple<T> = readonly [T?, ...T[]];
38
+ type UseTranslation<Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined> = (ns?: Ns, options?: UseTranslationOptions<KPrefix>) => UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
39
+ type AppWithTranslation = typeof appWithTranslation;
40
+ type TFunction = TFunction$1;
41
+ type I18n = i18n;
42
+ type WithTranslationHocType = typeof withTranslation;
43
+ type WithTranslation<Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined> = WithTranslation$1<Ns, KPrefix>;
44
+ type InitPromise = Promise<TFunction>;
45
+ type CreateClientReturn = {
46
+ i18n: I18n;
47
+ initPromise: InitPromise;
48
+ };
49
+ type SSRConfig = {
50
+ _nextI18Next?: {
51
+ initialI18nStore: any;
52
+ initialLocale: string;
53
+ ns: string[];
54
+ userConfig: UserConfig | null;
55
+ };
56
+ };
57
+ //#endregion
58
+ export { AppWithTranslation, CreateClientReturn, DefaultNamespace, I18n, I18nContext, InitPromise, InternalConfig, SSRConfig, TFunction, Trans, Translation, UseTranslation, UserConfig, WithTranslation, WithTranslationHocType, appWithTranslation, globalI18n as i18n, useTranslation, withTranslation };
59
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1,4 @@
1
+ import { appWithTranslation, globalI18n } from "./appWithTranslation.mjs";
2
+ import "./index.mjs";
3
+ import { I18nContext, Trans, Translation, useTranslation, withTranslation } from "react-i18next";
4
+ export { I18nContext, Trans, Translation, appWithTranslation, globalI18n as i18n, useTranslation, withTranslation };
@@ -0,0 +1,17 @@
1
+ import { useLayoutEffect } from "react";
2
+ import { FallbackLng } from "i18next";
3
+
4
+ //#region src/pagesRouter/utils.d.ts
5
+ declare const getFallbackForLng: (lng: string, fallbackLng: false | FallbackLng) => string[];
6
+ declare const unique: (list: string[]) => string[];
7
+ /**
8
+ * This hook behaves like `useLayoutEffect` on the client,
9
+ * and `useEffect` on the server(no effect).
10
+ *
11
+ * Since using `useLayoutEffect` on the server cause warning messages in nextjs,
12
+ * this hook is workaround for that.
13
+ */
14
+ declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
15
+ //#endregion
16
+ export { getFallbackForLng, unique, useIsomorphicLayoutEffect };
17
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1,26 @@
1
+ import { useEffect, useLayoutEffect } from "react";
2
+ //#region src/pagesRouter/utils.ts
3
+ const getFallbackForLng = (lng, fallbackLng) => {
4
+ if (typeof fallbackLng === "string") return [fallbackLng];
5
+ if (Array.isArray(fallbackLng)) return fallbackLng;
6
+ if (typeof fallbackLng === "object") {
7
+ const fallbackList = fallbackLng[lng];
8
+ const fallbackDefault = fallbackLng.default;
9
+ return [...fallbackList ?? [], ...fallbackDefault ?? []];
10
+ }
11
+ if (typeof fallbackLng === "function") return getFallbackForLng(lng, fallbackLng(lng));
12
+ return [];
13
+ };
14
+ const unique = (list) => Array.from(new Set(list));
15
+ /**
16
+ * This hook behaves like `useLayoutEffect` on the client,
17
+ * and `useEffect` on the server(no effect).
18
+ *
19
+ * Since using `useLayoutEffect` on the server cause warning messages in nextjs,
20
+ * this hook is workaround for that.
21
+ */
22
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
23
+ //#endregion
24
+ export { getFallbackForLng, unique, useIsomorphicLayoutEffect };
25
+
26
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/pagesRouter/utils.ts"],"sourcesContent":["import { FallbackLng, FallbackLngObjList } from 'i18next'\nimport { useLayoutEffect, useEffect } from 'react'\n\nexport const getFallbackForLng = (\n lng: string,\n fallbackLng: false | FallbackLng\n): string[] => {\n if (typeof fallbackLng === 'string') {\n return [fallbackLng]\n }\n\n if (Array.isArray(fallbackLng)) {\n return fallbackLng\n }\n\n if (typeof fallbackLng === 'object') {\n const fallbackList = (fallbackLng as FallbackLngObjList)[lng]\n const fallbackDefault = (fallbackLng as FallbackLngObjList)\n .default\n return [...(fallbackList ?? []), ...(fallbackDefault ?? [])]\n }\n\n if (typeof fallbackLng === 'function') {\n return getFallbackForLng(lng, fallbackLng(lng))\n }\n\n return []\n}\n\nexport const unique = (list: string[]) =>\n Array.from(new Set<string>(list))\n\n/**\n * This hook behaves like `useLayoutEffect` on the client,\n * and `useEffect` on the server(no effect).\n *\n * Since using `useLayoutEffect` on the server cause warning messages in nextjs,\n * this hook is workaround for that.\n */\nexport const useIsomorphicLayoutEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect\n"],"mappings":";;AAGA,MAAa,qBACX,KACA,gBACa;AACb,KAAI,OAAO,gBAAgB,SACzB,QAAO,CAAC,YAAY;AAGtB,KAAI,MAAM,QAAQ,YAAY,CAC5B,QAAO;AAGT,KAAI,OAAO,gBAAgB,UAAU;EACnC,MAAM,eAAgB,YAAmC;EACzD,MAAM,kBAAmB,YACtB;AACH,SAAO,CAAC,GAAI,gBAAgB,EAAE,EAAG,GAAI,mBAAmB,EAAE,CAAE;;AAG9D,KAAI,OAAO,gBAAgB,WACzB,QAAO,kBAAkB,KAAK,YAAY,IAAI,CAAC;AAGjD,QAAO,EAAE;;AAGX,MAAa,UAAU,SACrB,MAAM,KAAK,IAAI,IAAY,KAAK,CAAC;;;;;;;;AASnC,MAAa,4BACX,OAAO,WAAW,cAAc,kBAAkB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-i18next",
3
- "version": "16.0.6",
3
+ "version": "16.0.7",
4
4
  "repository": "git@github.com:i18next/next-i18next.git",
5
5
  "author": "i18next",
6
6
  "funding": [
@@ -72,12 +72,24 @@
72
72
  }
73
73
  },
74
74
  "./pages": {
75
- "types": "./dist/pagesRouter/index.d.cts",
76
- "default": "./dist/pagesRouter/index.cjs"
75
+ "import": {
76
+ "types": "./dist/pagesRouter/index.d.mts",
77
+ "default": "./dist/pagesRouter/index.mjs"
78
+ },
79
+ "require": {
80
+ "types": "./dist/pagesRouter/index.d.cts",
81
+ "default": "./dist/pagesRouter/index.cjs"
82
+ }
77
83
  },
78
84
  "./pages/serverSideTranslations": {
79
- "types": "./dist/pagesRouter/serverSideTranslations.d.cts",
80
- "default": "./dist/pagesRouter/serverSideTranslations.cjs"
85
+ "import": {
86
+ "types": "./dist/pagesRouter/serverSideTranslations.d.mts",
87
+ "default": "./dist/pagesRouter/serverSideTranslations.mjs"
88
+ },
89
+ "require": {
90
+ "types": "./dist/pagesRouter/serverSideTranslations.d.cts",
91
+ "default": "./dist/pagesRouter/serverSideTranslations.cjs"
92
+ }
81
93
  },
82
94
  "./package.json": "./package.json"
83
95
  },