@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.27 → 3.5.0-ultramodern.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/runtime/hooks.d.ts +5 -0
- package/dist/types/runtime/utils.d.ts +7 -2
- package/package.json +10 -10
- package/src/runtime/core.tsx +3 -3
- package/src/runtime/hooks.ts +3 -0
- package/src/runtime/utils.ts +7 -5
- package/tests/reactI18nextRuntimeBoundary.test.ts +1 -1
- package/tests/type-fixture/fixture-globals.d.ts +11 -0
- package/tests/type-fixture/tsconfig.json +1 -0
|
@@ -4,6 +4,11 @@ import type { LocalisedUrlsOption } from '../shared/localisedUrls';
|
|
|
4
4
|
import type { I18nInstance } from './i18n';
|
|
5
5
|
interface RuntimeContextWithI18n extends TRuntimeContext {
|
|
6
6
|
i18nInstance?: I18nInstance;
|
|
7
|
+
ssrContext?: {
|
|
8
|
+
request?: {
|
|
9
|
+
pathname?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
7
12
|
}
|
|
8
13
|
export declare function createContextValue(lang: string, i18nInstance: I18nInstance | undefined, entryName: string | undefined, languages: string[], localePathRedirect: boolean, ignoreRedirectRoutes: string[] | ((pathname: string) => boolean) | undefined, localisedUrls: LocalisedUrlsOption | undefined, setLang: (lang: string) => void): {
|
|
9
14
|
language: string;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { type TInternalRuntimeContext } from '@modern-js/runtime/context';
|
|
2
1
|
import type { LocalisedUrlsOption } from '../shared/localisedUrls';
|
|
3
|
-
export declare const getPathname: (context:
|
|
2
|
+
export declare const getPathname: (context: {
|
|
3
|
+
ssrContext?: {
|
|
4
|
+
request?: {
|
|
5
|
+
pathname?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
}) => string;
|
|
4
9
|
export declare const getEntryPath: () => string;
|
|
5
10
|
/**
|
|
6
11
|
* Helper function to get language from current pathname
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.5.0-ultramodern.
|
|
20
|
+
"version": "3.5.0-ultramodern.29",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -97,15 +97,15 @@
|
|
|
97
97
|
"i18next-fs-backend": "^2.6.6",
|
|
98
98
|
"i18next-http-backend": "^4.0.0",
|
|
99
99
|
"i18next-http-middleware": "^3.9.7",
|
|
100
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.
|
|
101
|
-
"@modern-js/
|
|
102
|
-
"@modern-js/runtime
|
|
103
|
-
"@modern-js/
|
|
104
|
-
"@modern-js/
|
|
105
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.
|
|
100
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.29",
|
|
101
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.29",
|
|
102
|
+
"@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.5.0-ultramodern.29",
|
|
103
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.29",
|
|
104
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.29",
|
|
105
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.29"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
|
-
"@modern-js/runtime": "3.5.0-ultramodern.
|
|
108
|
+
"@modern-js/runtime": "3.5.0-ultramodern.29",
|
|
109
109
|
"i18next": ">=26.3.1",
|
|
110
110
|
"react": "^19.2.7",
|
|
111
111
|
"react-dom": "^19.2.7",
|
|
@@ -129,8 +129,8 @@
|
|
|
129
129
|
"react-i18next": "17.0.8",
|
|
130
130
|
"ts-node": "^10.9.2",
|
|
131
131
|
"typescript": "^6.0.3",
|
|
132
|
-
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.
|
|
133
|
-
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.
|
|
132
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.29",
|
|
133
|
+
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.29"
|
|
134
134
|
},
|
|
135
135
|
"sideEffects": false,
|
|
136
136
|
"publishConfig": {
|
package/src/runtime/core.tsx
CHANGED
|
@@ -121,7 +121,7 @@ export const createI18nPlugin =
|
|
|
121
121
|
return loadReactI18nextIntegration?.() ?? null;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
api.onBeforeRender(async context => {
|
|
124
|
+
api.onBeforeRender(async (context: RuntimeContextWithI18n) => {
|
|
125
125
|
const {
|
|
126
126
|
useI18nextBackend,
|
|
127
127
|
changeI18nLanguage,
|
|
@@ -228,8 +228,8 @@ export const createI18nPlugin =
|
|
|
228
228
|
};
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
-
api.wrapRoot(App => {
|
|
232
|
-
return props => {
|
|
231
|
+
api.wrapRoot((App: React.ComponentType<any>) => {
|
|
232
|
+
return (props: Record<string, unknown>) => {
|
|
233
233
|
const runtimeContext = useContext(
|
|
234
234
|
RuntimeContext,
|
|
235
235
|
) as RuntimeContextWithI18n;
|
package/src/runtime/hooks.ts
CHANGED
|
@@ -21,6 +21,9 @@ import {
|
|
|
21
21
|
|
|
22
22
|
interface RuntimeContextWithI18n extends TRuntimeContext {
|
|
23
23
|
i18nInstance?: I18nInstance;
|
|
24
|
+
// Present when the context actually is the internal runtime context;
|
|
25
|
+
// getPathname only ever reads this on the server.
|
|
26
|
+
ssrContext?: { request?: { pathname?: string } };
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
function createMinimalI18nInstance(language: string): I18nInstance {
|
package/src/runtime/utils.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { isBrowser } from '@modern-js/runtime';
|
|
2
|
-
import {
|
|
3
|
-
getGlobalBasename,
|
|
4
|
-
type TInternalRuntimeContext,
|
|
5
|
-
} from '@modern-js/runtime/context';
|
|
2
|
+
import { getGlobalBasename } from '@modern-js/runtime/context';
|
|
6
3
|
import type { LocalisedUrlsOption } from '../shared/localisedUrls';
|
|
7
4
|
import { localiseTargetPathname } from '../shared/localisedUrls';
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
// Structural parameter: hooks.ts passes a public-TRuntimeContext-based
|
|
7
|
+
// context while core.tsx passes the internal one; both carry the request
|
|
8
|
+
// pathname shape this helper needs.
|
|
9
|
+
export const getPathname = (context: {
|
|
10
|
+
ssrContext?: { request?: { pathname?: string } };
|
|
11
|
+
}): string => {
|
|
10
12
|
if (isBrowser()) {
|
|
11
13
|
return window.location.pathname;
|
|
12
14
|
}
|
|
@@ -7,7 +7,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
7
7
|
const runtimeRoot = resolve(__dirname, '../src/runtime');
|
|
8
8
|
|
|
9
9
|
const readRuntimeSource = (file: string) =>
|
|
10
|
-
readFileSync(resolve(runtimeRoot, file), 'utf8');
|
|
10
|
+
readFileSync(resolve(runtimeRoot, file), 'utf8').replace(/\r\n/gu, '\n');
|
|
11
11
|
|
|
12
12
|
describe('react-i18next runtime boundary', () => {
|
|
13
13
|
test('keeps the disabled runtime entry free of the optional adapter edge', () => {
|