HTML 输入文件 - 如何翻译“选择文件”和“未选择文件”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14340519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:58:41  来源:igfitidea点击:

HTML input file - how to translate "Choose File" and "No file Chosen"?

htmldjangofilechooser

提问by 0xmtn

I know that these two words get automatically translated, due to the browser language. But my HTML is not doing that.

我知道由于浏览器语言,这两个词会自动翻译。但是我的 HTML 没有这样做。

HTML:

HTML:

<p>
  <label for="id_company_logo">
     Company Logo:
  </label>
  <input type="file" name="company_logo" id="id_company_logo" />
</p>

It is generated from following "form" code of django:

它是从以下“表单”代码生成的django

company_logo = forms.ImageField(label=_('Company Logo'),required=False, error_messages = {'invalid':_("Image files only")}, widget=forms.FileInput)

Am I doing anything wrong? I searched around for some time now, but I had absolutely no luck.

我做错了什么吗?我已经搜索了一段时间,但我绝对没有运气。

Thanks in advance.

提前致谢。

回答by Dragos

This problem was disscused several times on Stackoverflow.
Here are the articles:
How to change the button text of input type=“file” ?
Labeling file upload button
Change default text in input type=“file”?

这个问题在 Stackoverflow 上讨论过多次。
以下是文章:
如何更改 input type="file" 的按钮文本?
标签文件上传按钮
更改输入类型=“文件”中的默认文本?

But thisis a great article.

但是,是一个伟大的文章。

Hereyou can find a solution to your problem.

在这里,您可以找到解决问题的方法。

回答by Rajib Ganguly

Please sue this.

请起诉这个。

.upload-btn-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
  background-color: #fff;
  border: 1px solid #cdcdcd;
  border-radius: 3px;
  padding: 8px 12px;
  height: 39px!important;
  width:calc(100% - 26px);
}

.upload-btn-wrapper .btnr {
  border: 1px solid gray;
  color: gray;
  background-color: #eee;
  padding: 5px 10px;
  border-radius: 1px;
  font-size: 14px;
  font-weight: bold;
  position: relative;
}
.upload-btn-wrapper .btnr + span {
  padding: 5px;
  font-weight: normal;
  }

.upload-btn-wrapper input[type=file] {
    font-size: 42px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
}
<div class="upload-btn-wrapper">
  <button class="btnr" title="haga clic para cargar el archivo">Seleccionar archivos</button>
  <span>No hay archivos elegidos</span>
  <input type="file" name="myfile" title="haga clic para cargar el archivo" />
</div>

And css and run to see

和css并运行看看