Step 5: Use translation in components<\/h4> 'use client';\n\nimport { useTranslations } from 'next-intl';\n\nexport default function Welcome() {\n const t = useTranslations('common');\n return {t('welcome')}<\/h1>;\n}<\/pre>
It can also be used in Server Component:<\/p>
import { getTranslations } from 'next-intl\/server';\n\nexport default async function About() {\n const t = await getTranslations('about');\n return {t('title')}<\/h1>;\n}<\/pre>
? 3. Dynamic language switching (language selector)<\/h3>
Create a language switch component:<\/p>
'use client';\n\nimport { useRouter, usePathname } from 'next\/navigation';\nimport { useLocale } from 'next-intl';\n\nexport function LanguageSwitcher() {\n const router = useRouter();\n const pathname = usePathname();\n const locale = useLocale();\n\n const switchTo = (newLocale: string) => {\n \/\/ Convert the current path from \/en\/pathname to \/zh\/pathname\n router.push(pathname.replace(`\/${locale}`, `\/${newLocale}`));\n };\n\n Return (\n \n