## Summary
- Fixed translation key format compatibility with next-intl
- Fixed pluralization format from i18next to next-intl format
- Fixed dynamic translation key error handling
- Updated server components to match API response structure
- Fixed useSearchParams import location
## Changes
- Changed pluralization from `{{count}} items` to `{count} items` format
- Added proper error handling for missing translation keys
- Fixed import paths for next-intl hooks
- Fixed PartyPageClient trying to set non-existent appState.parties
## Test plan
- [x] Verified translations render correctly
- [x] Tested pluralization works with different counts
- [x] Confirmed no console errors about missing translations
- [x] Tested party page functionality
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
'use client'
|
|
import React, { PropsWithChildren, useEffect, useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import { usePathname } from 'next/navigation'
|
|
import { setCookie } from 'cookies-next'
|
|
import { retrieveLocaleCookies } from '~utils/retrieveCookies'
|
|
import * as SwitchPrimitive from '@radix-ui/react-switch'
|
|
import styles from './index.module.scss'
|
|
|
|
interface Props extends SwitchPrimitive.SwitchProps {}
|
|
|
|
export const LanguageSwitch = React.forwardRef<HTMLButtonElement, Props>(
|
|
function LanguageSwitch(
|
|
{ children }: PropsWithChildren<Props>,
|
|
forwardedRef
|
|
) {
|
|
// Router and locale data
|
|
const router = useRouter()
|
|
const pathname = usePathname()
|
|
const localeData = retrieveLocaleCookies()
|
|
|
|
// State
|
|
const [languageChecked, setLanguageChecked] = useState(false)
|
|
|
|
// Hooks
|
|
useEffect(() => {
|
|
setLanguageChecked(localeData === 'ja' ? true : false)
|
|
}, [localeData])
|
|
|
|
function changeLanguage(value: boolean) {
|
|
const language = value ? 'ja' : 'en'
|
|
const expiresAt = new Date()
|
|
expiresAt.setDate(expiresAt.getDate() + 120)
|
|
|
|
setCookie('NEXT_LOCALE', language, { path: '/', expires: expiresAt })
|
|
router.refresh()
|
|
}
|
|
|
|
return (
|
|
<SwitchPrimitive.Root
|
|
className={styles.languageSwitch}
|
|
onCheckedChange={changeLanguage}
|
|
checked={languageChecked}
|
|
ref={forwardedRef}
|
|
>
|
|
<SwitchPrimitive.Thumb className={styles.thumb} />
|
|
<span className={styles.left}>JP</span>
|
|
<span className={styles.right}>EN</span>
|
|
</SwitchPrimitive.Root>
|
|
)
|
|
}
|
|
)
|
|
|
|
export default LanguageSwitch
|