Skip to main content
Gradio provides internationalization support through the I18n and I18nData classes.

I18n

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

Parameters

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.

Methods

call

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.
str
required
The key to identify the translation string (e.g., “submit_button”).
I18nData
A I18nData object containing the translation key.

Properties

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.

Example

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

str
required
The translation key to be translated in the frontend.

Methods

to_dict

Convert the I18nData object to a dictionary for serialization. This allows the frontend to recognize it as a translatable object.
dict[str, Any]
A dictionary representation of the I18nData object.

Properties

str
The translation key.

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