> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
> Use this file to discover all available pages before exploring further.

# Internationalization (i18n)

Gradio provides internationalization support through the I18n and I18nData classes.

## I18n

```python theme={null}
gr.I18n(**translations)
```

Handles internationalization (i18n) for Gradio applications. Stores translation dictionaries and provides a method to retrieve translation keys.

### Parameters

<ParamField path="translations" type="dict[str, dict[str, str]]">
  Each keyword argument should be a locale code (e.g., "en", "fr") with a dictionary value, which maps translation keys to translated strings.
</ParamField>

### Methods

#### **call**

```python theme={null}
i18n(key)
```

Returns an I18nData object containing the translation key. This metadata object will be serialized and sent to the frontend, where it will be translated by the frontend's i18n system.

<ParamField path="key" type="str" required>
  The key to identify the translation string (e.g., "submit\_button").
</ParamField>

<ResponseField name="returns" type="I18nData">
  A I18nData object containing the translation key.
</ResponseField>

### Properties

<ResponseField name="translations_dict" type="dict[str, dict[str, str]]">
  Returns the dictionary of translations provided during initialization. These can be passed to the frontend for use in its translation system.
</ResponseField>

### Example

```python theme={null}
import gradio as gr

i18n = gr.I18n(
    en={"greeting": "Hello", "submit": "Submit"},
    es={"greeting": "Hola", "submit": "Enviar"},
    fr={"greeting": "Bonjour", "submit": "Soumettre"}
)

with gr.Blocks() as demo:
    gr.Textbox(label=i18n("greeting"))
    gr.Button(i18n("submit"))

demo.launch()
```

## I18nData

```python theme={null}
class I18nData
```

A class that wraps a translation key with metadata. This object will be serialized and sent to the frontend, where the actual translation will happen using the frontend's i18n system.

### Constructor

```python theme={null}
I18nData(key)
```

<ParamField path="key" type="str" required>
  The translation key to be translated in the frontend.
</ParamField>

### Methods

#### to\_dict

```python theme={null}
to_dict()
```

Convert the I18nData object to a dictionary for serialization. This allows the frontend to recognize it as a translatable object.

<ResponseField name="returns" type="dict[str, Any]">
  A dictionary representation of the I18nData object.
</ResponseField>

### Properties

<ResponseField name="key" type="str">
  The translation key.
</ResponseField>

## Usage Notes

* Locale codes should follow BCP 47 format (e.g., 'en', 'en-US', 'fr', 'es')
* Translation lookup happens on the frontend based on the browser's locale and the provided translation dictionaries
* You can use I18nData objects anywhere you would use a string in Gradio components
* The actual translation is performed in the frontend, allowing for dynamic language switching based on user preferences

## Advanced Example

```python theme={null}
import gradio as gr

i18n = gr.I18n(
    en={
        "app_title": "My Application",
        "input_label": "Enter your text",
        "output_label": "Result",
        "submit_btn": "Process",
        "description": "This is a sample application"
    },
    es={
        "app_title": "Mi Aplicación",
        "input_label": "Ingrese su texto",
        "output_label": "Resultado",
        "submit_btn": "Procesar",
        "description": "Esta es una aplicación de muestra"
    },
    fr={
        "app_title": "Mon Application",
        "input_label": "Entrez votre texte",
        "output_label": "Résultat",
        "submit_btn": "Traiter",
        "description": "Ceci est une application exemple"
    }
)

def process_text(text):
    return text.upper()

with gr.Blocks(title=i18n("app_title")) as demo:
    gr.Markdown(i18n("description"))
    with gr.Row():
        input_text = gr.Textbox(label=i18n("input_label"))
        output_text = gr.Textbox(label=i18n("output_label"))
    btn = gr.Button(i18n("submit_btn"))
    btn.click(process_text, input_text, output_text)

demo.launch()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.