Skip to content

Commit 8b1e032

Browse files
committed
Merge branch 'release/1.0.5'
2 parents f9cfd32 + 32f1fb9 commit 8b1e032

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.0.5] - 2023-07-28
6+
7+
### <!-- 02 -->Bug Fixes
8+
9+
- Remove close function from locale switcher component
10+
11+
### <!-- 04 -->Refactor
12+
13+
- Improve code formatting and remove unused import
14+
- Simplify locale switching logic in `useLocaleSwitcher`
15+
516
## [1.0.4] - 2023-07-28
617

718
### <!-- 01 -->Features

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-lingui-template",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src/components/locale-switcher.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export function LocaleSwitcher() {
4545
)}
4646
onClick={() => {
4747
changeLocale(locale)
48-
close()
4948
}}
5049
>
5150
{getLocaleName(locale)}

src/hooks/use-locale-switcher.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ export function useLocaleSwitcher() {
88
const locale = useLocale()
99

1010
const changeLocale = useCallback(
11-
async (nextLocale: Locale) => {
11+
(nextLocale: Locale) => {
1212
if (!nextLocale || nextLocale === locale) {
1313
return
1414
}
1515

16-
let pathName = router.pathname
17-
Object.keys(router.query).forEach((k) => {
18-
if (k === 'locale') {
19-
pathName = pathName.replace(`[${k}]`, nextLocale)
20-
return
21-
}
22-
pathName = pathName.replace(`[${k}]`, <string>router.query[k])
23-
})
16+
const pathName = Object.keys(router.query).reduce(
17+
(currentPathName, k) => {
18+
if (k === 'locale') {
19+
return currentPathName.replace(`[${k}]`, nextLocale)
20+
}
21+
return currentPathName.replace(`[${k}]`, String(router.query[k]))
22+
},
23+
router.pathname,
24+
)
2425

25-
await router.replace(pathName)
26+
router.replace(pathName)
2627
},
2728
[locale, router],
2829
)

src/hooks/use-locale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getLocale,Locale } from '@/utils/locales'
1+
import { getLocale, Locale } from '@/utils/locales'
22
import { useRouter } from 'next/router'
33

44
export function useLocale(): Locale {

src/pages/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {defaultLocale, getLocale, loadCatalog} from '@/utils/locales'
2-
import { GetStaticPropsContext } from 'next'
1+
import { getLocale, loadCatalog } from '@/utils/locales'
32
import { useRouter } from 'next/router'
43
import { useEffect } from 'react'
54

0 commit comments

Comments
 (0)