\n \n {children}\n <\/NextIntlClientProvider>\n <\/body>\n <\/html>\n );\n}<\/pre>

步驟五:在組件中使用翻譯<\/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>

也可以在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. 動態(tài)語言切換(語言選擇器)<\/h3>

創(chuàng)建一個語言切換組件:<\/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    \/\/ 將當(dāng)前路徑從\/en\/pathname 轉(zhuǎn)為\/zh\/pathname\n    router.push(pathname.replace(`\/${locale}`, `\/${newLocale}`));\n  };\n\n  return (\n    
\n
      <noframes id="wk8ss"><tfoot id="wk8ss"></tfoot></noframes>
      <noframes id="wk8ss"><tbody id="wk8ss"></tbody></noframes>
      <tbody id="wk8ss"></tbody>