@akinon/next 1.91.0-rc.0 → 1.91.0-rc.2
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 +8 -0
- package/hooks/use-localization.ts +24 -10
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -25,19 +25,33 @@ export const useLocalization = () => {
|
|
|
25
25
|
* @param locale Locale value defined in the settings.
|
|
26
26
|
*/
|
|
27
27
|
const setLocale = (locale: string) => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
|
|
31
|
-
? ''
|
|
32
|
-
: `/${locale}`;
|
|
28
|
+
const { protocol, hostname, port, search, pathname } = location;
|
|
29
|
+
const pathnameWithoutLocale = pathname.replace(urlLocaleMatcherRegex, '');
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
let targetUrl;
|
|
32
|
+
|
|
33
|
+
if (localeUrlStrategy === LocaleUrlStrategy.Subdomain) {
|
|
34
|
+
const hostParts = hostname.split('.');
|
|
35
|
+
const subDomain = hostParts[0];
|
|
36
|
+
const isSubdomainLocale = locales.some((loc) => loc.value === subDomain);
|
|
37
|
+
const baseDomain = isSubdomainLocale
|
|
38
|
+
? hostParts.slice(1).join('.')
|
|
39
|
+
: hostname;
|
|
40
|
+
|
|
41
|
+
const formattedPort = port ? `:${port}` : '';
|
|
42
|
+
|
|
43
|
+
targetUrl = `${protocol}//${locale}.${baseDomain}${formattedPort}${pathnameWithoutLocale}${search}`;
|
|
44
|
+
} else {
|
|
45
|
+
const shouldHideLocale =
|
|
46
|
+
locale === defaultLocaleValue &&
|
|
47
|
+
localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales;
|
|
48
|
+
const localePath = shouldHideLocale ? '' : `/${locale}`;
|
|
49
|
+
|
|
50
|
+
targetUrl = `${localePath}${pathnameWithoutLocale}${search}`;
|
|
51
|
+
}
|
|
38
52
|
|
|
39
53
|
// router.push is not used because reloading the page also clears the client side cache.
|
|
40
|
-
location.href =
|
|
54
|
+
location.href = targetUrl;
|
|
41
55
|
};
|
|
42
56
|
|
|
43
57
|
/**
|
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.91.0-rc.
|
|
4
|
+
"version": "1.91.0-rc.2",
|
|
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.91.0-rc.
|
|
37
|
+
"@akinon/eslint-plugin-projectzero": "1.91.0-rc.2",
|
|
38
38
|
"@types/react-redux": "7.1.30",
|
|
39
39
|
"@types/set-cookie-parser": "2.4.7",
|
|
40
40
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|