/*思路定义def函数*/
def generate_css(language):
if language == 'en':
before_content = "Drag files here"
after_content = "The maximum limit for each file is 200MB."
button_content = "Browse file"
else:
before_content = "将文件拖放到此处"
after_content = "每个文件最大限制200MB"
button_content = "浏览文件"
css = f'''
<style>
[data-testid="stFileUploaderDropzone"] div div::before {{
content: "{before_content}";
}}
[data-testid="stFileUploaderDropzone"] div div span {{
display: none;
}}
[data-testid="stFileUploaderDropzone"] div div::after {{
color: rgba(49, 51, 63, 0.6);
font-size: .8em;
content: "{after_content}";
}}
[data-testid="stFileUploaderDropzone"] div div small {{
display: none;
}}
[data-testid="stFileUploaderDropzone"] [data-testid="stBaseButton-secondary"] {{
font-size: 0px;
}}
[data-testid="stFileUploaderDropzone"] [data-testid="stBaseButton-secondary"]::after {{
content: "{button_content}";
font-size: 17px !important;
}}
</style>
'''
return css
的最后需要设置st.markdown(css, unsafe_allow_html=True),这样就可以在中英文页面显示不同的,然后需要根据页面不同设置 css = generate_css('en')或者 css = generate_css('cn'),需注意若不能正常显示需要修改data-testid,在浏览器进入f12查看id后修改