> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/frameworks-and-ai/react/getting-started.md).

# Getting started

Install the Weglot package on your Next.js or Vite app.

## Requirements

| Requirement                              | Version                |
| ---------------------------------------- | ---------------------- |
| Node.js                                  | 20.9 or later          |
| React                                    | 19                     |
| Next.js (App Router), if you use Next.js | 15, or 16.0.4 or later |

You also need a **Weglot 2.0** project. [Sign in to Weglot 2.0](https://auth.weglot.com/), create a project with its source and target languages, then copy its API key: in your project settings, under **API key**. It starts with `pk_`.

## 1. Install the package

```bash
npm install @weglot/translate-react
```

## 2. Add your API key

Add it to the `.env` file at the root of your app, and keep this file out of version control:

```bash
# .env
WEGLOT_API_KEY=pk_your_weglot_api_key
```

## 3. Add the plugin

{% tabs %}
{% tab title="Next.js" %}
Wrap your Next.js configuration with `withWeglot`. Set `sourceRoot` to the folder that contains all your pages and components:

```ts
// next.config.ts
import type { NextConfig } from "next";
import { withWeglot } from "@weglot/translate-react/next";

const nextConfig: NextConfig = {};

export default async function (): Promise<NextConfig> {
  return await withWeglot(nextConfig, { sourceRoot: "./app" });
}
```

{% endtab %}

{% tab title="Vite" %}

```ts
// vite.config.ts
import { defineConfig } from "vite";
import { weglotPlugin } from "@weglot/translate-react/vite";

export default defineConfig({
  plugins: [weglotPlugin({ sourceRoot: "src" })],
});
```

{% endtab %}
{% endtabs %}

With Webpack, use `weglotPlugin` from `@weglot/translate-react/webpack` the same way.

## 4. Add the provider

Wrap your app with `WeglotProvider`, as early as possible:

{% tabs %}
{% tab title="Next.js" %}
Import the Next.js provider, from `@weglot/translate-react/react/next`, so that changing language refreshes your server components:

```tsx
// app/layout.tsx
import { WeglotProvider } from "@weglot/translate-react/react/next";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <WeglotProvider>{children}</WeglotProvider>
      </body>
    </html>
  );
}
```

{% endtab %}

{% tab title="Vite" %}

```tsx
// src/main.tsx
import { WeglotProvider } from "@weglot/translate-react/react";

root.render(
  <WeglotProvider>
    <App />
  </WeglotProvider>,
);
```

{% endtab %}
{% endtabs %}

## 5. Ignore the generated files

Each build writes `public/translations/<locale>.json`: add this folder to your `.gitignore`.

The translations received from Weglot are kept in `<sourceRoot>/weglot/cache/<locale>.json`. Commit this folder to build without calling the API (see [Build modes](/frameworks-and-ai/react/settings.md#build-modes)), or ignore it and let each build fetch the translations it lacks.

Text written in your code is now translated. To let visitors change language, add a [language switcher](/frameworks-and-ai/react/use-cases.md#add-a-language-switcher). To translate content from a CMS or an API, see [Dynamic content](/frameworks-and-ai/react/dynamic-content.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.weglot.com/frameworks-and-ai/react/getting-started.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
