File size: 1,016 Bytes
3042d91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr

# Create an i18n instance with translations for different languages
i18n = gr.i18n(
    en={"name_label": "Your Name", "submit_button": "Greet", "john_doe": "John English"},
    es={"name_label": "Tu Nombre", "submit_button": "Saludar", "john_doe": "John Spanish"},
    fr={"name_label": "Votre Nom", "submit_button": "Saluer", "john_doe": "John French"},
    de={"name_label": "Dein Name", "submit_button": "Grüßen", "john_doe": "John German"},
)

with gr.Blocks() as demo:
    with gr.Row():
        name_input = gr.Textbox(label=i18n("name_label"), value=i18n("john_doe"))

    with gr.Row():
        greet_btn = gr.Button(i18n("submit_button"))
        goodbye_btn = gr.Button("Cancel")

    gr.Markdown("""
    This demo shows Gradio's internationalization (i18n) functionality. 
    The interface automatically displays text in the user's browser language 
    (if available in our translations), or falls back to English.
    """)

if __name__ == "__main__":
    demo.launch(i18n=i18n)