Skip to main content

Server Components

This guide explains how to use the internationalization package with React Server Components in your Next.js application.

Overview

Server Components are rendered on the server and can directly access server-side resources. With the internationalization package, you can load translations directly in your Server Components without additional client-side JavaScript.

Loading Translations

To use translations in a Server Component, import the getDictionary function and use it to load the appropriate dictionary based on the locale:
The getDictionary function:
  1. Takes a locale string as input
  2. Loads the corresponding dictionary file
  3. Returns the dictionary object with all translations for that locale

Accessing Nested Translations

Dictionary files are structured as nested objects. You can access nested translations using dot notation:

Working with Arrays

If your translations include arrays, you can map over them to render multiple elements:

Handling Dynamic Content

You can combine translations with dynamic content:

Fallback Handling

The getDictionary function includes built-in fallback handling. If a translation is not available in the requested locale, it will fall back to English:
You can also implement your own fallback logic for specific cases:

Metadata and SEO

You can use translations for page metadata to improve SEO:

Passing Translations to Client Components

To use translations in Client Components, you need to pass them from a Server Component:

Best Practices

Structure your translation files by feature or page to make them easier to manage:
Define types for your translations to get better IDE support and catch errors early:
Instead of concatenating strings:
Use placeholders:

Examples

Basic Page with Translations

Dynamic Routes with Translations

Next Steps

Client Components

Learn how to use translations in client components

Adding Languages

How to add support for new languages