Skip to content

Internationalization for client side components #57405

Answered by mass2527
llhooman asked this question in App Router
Discussion options

You must be logged in to vote

After adding the import statement import 'server-only' in the lib/dictionary.ts file, all the code in that file is now designated as server-only code and cannot be imported from a client component.

If you need to access the dictionary from a client component, you should call the server-only function getDictionary in the layout.tsx(server component) file and then pass its result to a provider.

For example:

// app/[lang]/layout.tsx

export default async function RootLayout({
  children,
  params,
}: {
  children: React.ReactNode
  params: { lang: Locale }
}) {
  const dictionary = await getDictionary(params.lang)

  return (
    <html lang={params.lang}>
      <body>
        <DictionaryProv…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@llhooman
Comment options

Comment options

You must be logged in to vote
5 replies
@llhooman
Comment options

@hichui
Comment options

@mass2527
Comment options

@beforedisappear
Comment options

@Haeyzed
Comment options

Answer selected by llhooman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants