@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.17 → 3.5.0-ultramodern.19

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.
@@ -167,6 +167,14 @@ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
167
167
  const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
168
168
  return localizedUrl;
169
169
  };
170
+ const createLocaleRedirectResponse = (location)=>new Response(null, {
171
+ status: 302,
172
+ headers: {
173
+ 'Cache-Control': 'private, no-store',
174
+ Location: location,
175
+ Vary: 'Accept-Language, Cookie'
176
+ }
177
+ });
170
178
  const i18nServerPlugin = (options)=>({
171
179
  name: '@modern-js/plugin-i18n/server',
172
180
  setup: (api)=>{
@@ -235,12 +243,12 @@ const i18nServerPlugin = (options)=>({
235
243
  if (i18nextDetector) detectedLanguage = c.get('language') || null;
236
244
  const targetLanguage = detectedLanguage || fallbackLanguage;
237
245
  const localizedUrl = buildLocalizedUrl(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
238
- return c.redirect(localizedUrl);
246
+ return createLocaleRedirectResponse(localizedUrl);
239
247
  }
240
248
  const localisedUrlsConfig = (0, localisedUrls_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
241
249
  if (localisedUrlsConfig.enabled) {
242
250
  const expectedUrl = buildLocalizedUrl(c.req, originUrlPath, language, languages, localisedUrls);
243
- if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return c.redirect(expectedUrl);
251
+ if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return createLocaleRedirectResponse(expectedUrl);
244
252
  }
245
253
  await next();
246
254
  }
@@ -132,6 +132,14 @@ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
132
132
  const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
133
133
  return localizedUrl;
134
134
  };
135
+ const createLocaleRedirectResponse = (location)=>new Response(null, {
136
+ status: 302,
137
+ headers: {
138
+ 'Cache-Control': 'private, no-store',
139
+ Location: location,
140
+ Vary: 'Accept-Language, Cookie'
141
+ }
142
+ });
135
143
  const i18nServerPlugin = (options)=>({
136
144
  name: '@modern-js/plugin-i18n/server',
137
145
  setup: (api)=>{
@@ -200,12 +208,12 @@ const i18nServerPlugin = (options)=>({
200
208
  if (i18nextDetector) detectedLanguage = c.get('language') || null;
201
209
  const targetLanguage = detectedLanguage || fallbackLanguage;
202
210
  const localizedUrl = buildLocalizedUrl(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
203
- return c.redirect(localizedUrl);
211
+ return createLocaleRedirectResponse(localizedUrl);
204
212
  }
205
213
  const localisedUrlsConfig = resolveLocalisedUrlsConfig(localisedUrls);
206
214
  if (localisedUrlsConfig.enabled) {
207
215
  const expectedUrl = buildLocalizedUrl(c.req, originUrlPath, language, languages, localisedUrls);
208
- if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return c.redirect(expectedUrl);
216
+ if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return createLocaleRedirectResponse(expectedUrl);
209
217
  }
210
218
  await next();
211
219
  }
@@ -133,6 +133,14 @@ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
133
133
  const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
134
134
  return localizedUrl;
135
135
  };
136
+ const createLocaleRedirectResponse = (location)=>new Response(null, {
137
+ status: 302,
138
+ headers: {
139
+ 'Cache-Control': 'private, no-store',
140
+ Location: location,
141
+ Vary: 'Accept-Language, Cookie'
142
+ }
143
+ });
136
144
  const i18nServerPlugin = (options)=>({
137
145
  name: '@modern-js/plugin-i18n/server',
138
146
  setup: (api)=>{
@@ -201,12 +209,12 @@ const i18nServerPlugin = (options)=>({
201
209
  if (i18nextDetector) detectedLanguage = c.get('language') || null;
202
210
  const targetLanguage = detectedLanguage || fallbackLanguage;
203
211
  const localizedUrl = buildLocalizedUrl(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
204
- return c.redirect(localizedUrl);
212
+ return createLocaleRedirectResponse(localizedUrl);
205
213
  }
206
214
  const localisedUrlsConfig = resolveLocalisedUrlsConfig(localisedUrls);
207
215
  if (localisedUrlsConfig.enabled) {
208
216
  const expectedUrl = buildLocalizedUrl(c.req, originUrlPath, language, languages, localisedUrls);
209
- if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return c.redirect(expectedUrl);
217
+ if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return createLocaleRedirectResponse(expectedUrl);
210
218
  }
211
219
  await next();
212
220
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.17",
20
+ "version": "3.5.0-ultramodern.19",
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/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.5.0-ultramodern.17",
101
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.17",
102
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.17",
103
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.17",
104
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.17",
105
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.17"
100
+ "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.5.0-ultramodern.19",
101
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.19",
102
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.19",
103
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.19",
104
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.19",
105
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.19"
106
106
  },
107
107
  "peerDependencies": {
108
- "@modern-js/runtime": "3.5.0-ultramodern.17",
108
+ "@modern-js/runtime": "3.5.0-ultramodern.19",
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.17",
133
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.17"
132
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.19",
133
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.19"
134
134
  },
135
135
  "sideEffects": false,
136
136
  "publishConfig": {
@@ -328,6 +328,16 @@ const buildLocalizedUrl = (
328
328
  return localizedUrl;
329
329
  };
330
330
 
331
+ const createLocaleRedirectResponse = (location: string): Response =>
332
+ new Response(null, {
333
+ status: 302,
334
+ headers: {
335
+ 'Cache-Control': 'private, no-store',
336
+ Location: location,
337
+ Vary: 'Accept-Language, Cookie',
338
+ },
339
+ });
340
+
331
341
  export const i18nServerPlugin = (options: I18nPluginOptions): ServerPlugin => ({
332
342
  name: '@modern-js/plugin-i18n/server',
333
343
  setup: api => {
@@ -475,7 +485,7 @@ export const i18nServerPlugin = (options: I18nPluginOptions): ServerPlugin => ({
475
485
  languages,
476
486
  localisedUrls,
477
487
  );
478
- return c.redirect(localizedUrl);
488
+ return createLocaleRedirectResponse(localizedUrl);
479
489
  }
480
490
  const localisedUrlsConfig =
481
491
  resolveLocalisedUrlsConfig(localisedUrls);
@@ -488,7 +498,7 @@ export const i18nServerPlugin = (options: I18nPluginOptions): ServerPlugin => ({
488
498
  localisedUrls,
489
499
  );
490
500
  if (expectedUrl !== `${pathname}${url.search}${url.hash}`) {
491
- return c.redirect(expectedUrl);
501
+ return createLocaleRedirectResponse(expectedUrl);
492
502
  }
493
503
  }
494
504
  await next();
@@ -509,7 +509,6 @@ describe('i18n server API prefix skips', () => {
509
509
  header: () => ({ host: 'localhost' }),
510
510
  },
511
511
  get: () => null,
512
- redirect: (url: string) => ({ redirectedTo: url }),
513
512
  }) as any;
514
513
 
515
514
  // Sanity: well-formed non-canonical slugs still redirect.
@@ -517,7 +516,10 @@ describe('i18n server API prefix skips', () => {
517
516
  createContext('/cs/products/bota'),
518
517
  async () => {},
519
518
  );
520
- expect(redirected).toEqual({ redirectedTo: '/cs/produkty/bota' });
519
+ expect(redirected.status).toBe(302);
520
+ expect(redirected.headers.get('location')).toBe('/cs/produkty/bota');
521
+ expect(redirected.headers.get('cache-control')).toBe('private, no-store');
522
+ expect(redirected.headers.get('vary')).toBe('Accept-Language, Cookie');
521
523
 
522
524
  // Malformed encoding must fall through to next() instead of throwing.
523
525
  let nextCalls = 0;