Spaces:
Paused
Paused
""" | |
提供简化的函数,用于翻译界面中的文本 | |
""" | |
from translate_ui import translate_text, translate_special_list | |
import gradio as gr | |
def t(text): | |
""" | |
翻译文本的简便方法 | |
Args: | |
text: 要翻译的文本 | |
Returns: | |
翻译后的文本 | |
""" | |
return translate_text(text) | |
def tr(component, text): | |
""" | |
翻译文本并设置到组件的相应属性 | |
Args: | |
component: 要设置文本的gradio组件 | |
text: 要翻译的文本 | |
Returns: | |
组件自身 | |
""" | |
if isinstance(component, (gr.Button, gr.UploadButton)): | |
component.value = translate_text(text) | |
elif isinstance(component, gr.Markdown): | |
component.value = translate_text(text) | |
elif isinstance(component, (gr.Textbox, gr.Number, gr.Slider, gr.Radio, gr.Checkbox, | |
gr.Dropdown, gr.Image, gr.Gallery, gr.CheckboxGroup)): | |
component.label = translate_text(text) | |
elif isinstance(component, (gr.Tab, gr.Accordion)): | |
component.label = translate_text(text) | |
return component | |
def translate_civitai_constants(app_instance): | |
""" | |
翻译特定于Civitai的常量 | |
Args: | |
app_instance: 应用实例 | |
Returns: | |
无 | |
""" | |
from modutils import CIVITAI_SORT, CIVITAI_PERIOD | |
# 查找包含这些常量的组件并翻译 | |
for component in app_instance.blocks.values(): | |
if hasattr(component, 'choices'): | |
if component.choices == CIVITAI_SORT: | |
component.choices = translate_special_list(CIVITAI_SORT, "civitai_sort") | |
elif component.choices == CIVITAI_PERIOD: | |
component.choices = translate_special_list(CIVITAI_PERIOD, "civitai_period") | |
def translate_app_title(title="# 🧩 图像扩散工坊", description="本应用是对r3gm的DiffuseCraft的修改版本。"): | |
""" | |
返回翻译好的应用标题和描述 | |
Args: | |
title: 自定义标题(可选) | |
description: 自定义描述(可选) | |
Returns: | |
(title, description)元组 | |
""" | |
return title, description |