Magic Translate
  • Getting started
  • Clients
    • React
      • The <T> component
      • The useT hook
      • Next.js
    • React SSR
      • The translate function
  • FAQs
    • How fast is the translation
    • How is the usage calculated
    • What are the limitations
    • What happens when the monthly limit is reached?
    • What are the available languages?
Powered by GitBook
On this page
  • Getting Started
  • Changing Languages
  • Example project
  1. Clients

React SSR

Magic Translate fully embraces React Server Components (RSC)

Getting Started

Install the react SSR client for Magic Translate in your application.

# using yarn
yarn add @magic-translate/react-ssr

# using npm
npm i @magic-translate/react-ssr

# using pnpm
pnpm install @magic-translate/react-ssr

Now it's time to configure your Magic Translate SSR client and the <T> component

// somewhere in your code, eg. ./lib/translate.ts

import { createT, setupTranslate } from "@magic-translate/react-ssr";

const magicTranslateConfig = {
  apiKey: "<your-api-key>",
}

export const translate = setupTranslate(magicTranslateConfig);

export const T = createT(translate);

Now you can use the translate component <T> in any React server component.

import { Language } from "@magic-translate/react-ssr";
import {
  T
} from './lib/translate' // ... or where ever you located the file above 

const SomeServerComponent = async () => (
  <T lang={Language.ZH}>Please translate me!</T>
)

And that's basically it! You can now translate your application effortlessly into over 70 languages 🤯

Changing Languages

To change the current language all you have to do is change the lang prop of the <T> component.

Example project

PreviousNext.jsNextThe translate function

Last updated 1 year ago

If you don't have an API key yet, please visit to get one.

Please note that the <T> component from React SSR only works within React server components. If you want to use Magic Translate in client components, please refer to the docs.

For more options of the <T> component please refer to the . The API of the <T> server component is identical to the API of the client <T> component.

You can find an example SSR project here:

magictranslate.io
React client
<T> component docs
https://github.com/magic-translate/magic-translate-example-react-ssr