@akinon/next 1.92.0-rc.28 → 1.92.0-rc.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/CHANGELOG.md +6 -0
- package/hooks/use-localization.ts +2 -3
- package/middlewares/default.ts +32 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,6 @@ import { LocalizationContext } from '../localization/provider';
|
|
|
4
4
|
import { useContext } from 'react';
|
|
5
5
|
import { setCookie, urlLocaleMatcherRegex } from '../utils';
|
|
6
6
|
import { LocaleUrlStrategy } from '../localization';
|
|
7
|
-
import { useRouter } from 'next/navigation';
|
|
8
7
|
|
|
9
8
|
export const useLocalization = () => {
|
|
10
9
|
const {
|
|
@@ -18,8 +17,6 @@ export const useLocalization = () => {
|
|
|
18
17
|
localeUrlStrategy
|
|
19
18
|
} = useContext(LocalizationContext);
|
|
20
19
|
|
|
21
|
-
const router = useRouter();
|
|
22
|
-
|
|
23
20
|
/**
|
|
24
21
|
* Sets the locale in the URL.
|
|
25
22
|
* @param locale Locale value defined in the settings.
|
|
@@ -30,6 +27,8 @@ export const useLocalization = () => {
|
|
|
30
27
|
|
|
31
28
|
let targetUrl;
|
|
32
29
|
|
|
30
|
+
setCookie('pz-locale', locale);
|
|
31
|
+
|
|
33
32
|
if (localeUrlStrategy === LocaleUrlStrategy.Subdomain) {
|
|
34
33
|
const hostParts = hostname.split('.');
|
|
35
34
|
const subDomain = hostParts[0];
|
package/middlewares/default.ts
CHANGED
|
@@ -401,6 +401,38 @@ const withPzDefault =
|
|
|
401
401
|
}
|
|
402
402
|
);
|
|
403
403
|
|
|
404
|
+
if (
|
|
405
|
+
!url.pathname.startsWith(
|
|
406
|
+
`/${currency}/orders`
|
|
407
|
+
)
|
|
408
|
+
) {
|
|
409
|
+
const currentCookieLocale =
|
|
410
|
+
req.cookies.get('pz-locale')?.value;
|
|
411
|
+
|
|
412
|
+
const urlHasExplicitLocale =
|
|
413
|
+
url.pathname.match(urlLocaleMatcherRegex);
|
|
414
|
+
const shouldUpdateCookie =
|
|
415
|
+
!currentCookieLocale ||
|
|
416
|
+
urlHasExplicitLocale;
|
|
417
|
+
|
|
418
|
+
if (shouldUpdateCookie) {
|
|
419
|
+
middlewareResult.cookies.set(
|
|
420
|
+
'pz-locale',
|
|
421
|
+
locale?.length > 0
|
|
422
|
+
? locale
|
|
423
|
+
: defaultLocaleValue,
|
|
424
|
+
{
|
|
425
|
+
domain: rootHostname,
|
|
426
|
+
sameSite: 'none',
|
|
427
|
+
secure: true,
|
|
428
|
+
expires: new Date(
|
|
429
|
+
Date.now() + 1000 * 60 * 60 * 24 * 7
|
|
430
|
+
) // 7 days
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
404
436
|
if (
|
|
405
437
|
req.cookies.get('pz-locale') &&
|
|
406
438
|
req.cookies.get('pz-locale').value !== locale
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/next",
|
|
3
3
|
"description": "Core package for Project Zero Next",
|
|
4
|
-
"version": "1.92.0-rc.
|
|
4
|
+
"version": "1.92.0-rc.29",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"set-cookie-parser": "2.6.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@akinon/eslint-plugin-projectzero": "1.92.0-rc.
|
|
37
|
+
"@akinon/eslint-plugin-projectzero": "1.92.0-rc.29",
|
|
38
38
|
"@babel/core": "7.26.10",
|
|
39
39
|
"@babel/preset-env": "7.26.9",
|
|
40
40
|
"@babel/preset-typescript": "7.27.0",
|