File size: 743 Bytes
baebd1e
 
f1597cc
 
baebd1e
 
f1597cc
 
baebd1e
 
f1597cc
 
 
 
 
 
 
baebd1e
f1597cc
baebd1e
f1597cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr

from gradio_i18n import Translate
from gradio_i18n import gettext as _


def greet(name, lang):
    return f"Hello {name} in {lang}!"


with gr.Blocks() as demo:
    gr.Markdown(value="> Check out [Repository](https://github.com/hoveychen/gradio-i18n) for more examples")
    lang = gr.Radio(choices=[("English", "en"), ("中文", "zh")], label=_("Language"))
    with Translate("translation.yaml", lang, placeholder_langs=["en", "zh"]):
        name = gr.Textbox(label=_("Name"), placeholder=_("Input your name here."))
        output = gr.Textbox(label=_("Greeting"))
        submit_btn = gr.Button(value=_("Submit"))

    submit_btn.click(greet, inputs=[name, lang], outputs=output)

demo.launch(server_name="0.0.0.0")