> 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/use-cases.md).

# Use cases

Customize how Weglot translates your React app.

## What gets translated

The plugin translates text written in JSX, and:

* string literals inside JSX expressions, such as `{ok ? "Saved" : "Not saved"}` or `{name || "Anonymous"}`;
* strings read from a constant, such as `{STATUSES[status]}` or `{LABELS.title}`;
* the `title`, `alt`, `label`, `placeholder`, `aria-label`, `aria-description`, `description`, `subtitle` and `content` attributes.

A sentence keeps its markup: `<p>Hello <strong>world</strong>, welcome</p>` is translated as one string, so the translation can place `<strong>` where the target language needs it.

The plugin leaves alone strings outside JSX (a `useState("idle")`, a route, an event name), identifiers and class names, URLs and file names, the content of `<code>`, `<pre>`, `<script>`, `<style>`, `<kbd>`, `<samp>` and `<var>`, and anything it cannot read statically.

## Exclude content from translation

Add `translate="no"` or `data-weglot-skip` to any element. Its content, and its children, stay in the original language.

```tsx
<span translate="no">Taskly</span>
<div data-weglot-skip>{customerQuote}</div>
```

## Translate your own component props

By default, only the built-in attributes listed above are translated. Use `translatableAttributes` to declare which of your components' props hold text. Each entry adds a prop name, or removes it with a `!` prefix. `"*"` applies first, then the component's own entry.

```ts
withWeglot(nextConfig, {
  sourceRoot: "./app",
  translatableAttributes: {
    "*": ["!label"],           // never translate `label`...
    Button: ["label"],         // ...except on Button
    PageTitle: ["heading"],
    "Select.Option": ["hint"], // only this Option
  },
});
```

Prop names are case-insensitive. Component keys are case-sensitive and use the exported name, so `import { PageTitle as PT }` still matches `PageTitle`.

## Add a language switcher

Use the `LocaleSwitcher` component, a dropdown of the languages you list:

```tsx
"use client";
import { LocaleSwitcher } from "@weglot/translate-react/react";

export function Header() {
  return (
    <LocaleSwitcher
      locales={[
        { code: "en", label: "English" },
        { code: "fr", label: "Français" },
      ]}
    />
  );
}
```

To match your own design, use `useWeglotContext`:

```tsx
"use client";
import { useWeglotContext } from "@weglot/translate-react/react";

const LANGUAGES = [
  { code: "en", label: "English" },
  { code: "fr", label: "Français" },
  { code: "es", label: "Español" },
];

export function LanguageMenu() {
  const { locale, setLocale } = useWeglotContext();
  return (
    <nav aria-label="Language" translate="no">
      {LANGUAGES.map(({ code, label }) => (
        <button key={code} aria-current={code === locale} onClick={() => setLocale(code)}>
          {label}
        </button>
      ))}
    </nav>
  );
}
```

The visitor's language is stored in a cookie (see `localePersistence` in [Settings](https://developers.weglot.com/frameworks-and-ai/react/settings.md)). All languages are served on the same URLs, so search engines only index the source language.


---

# 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/use-cases.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.
