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

戏子无情 提交于 2019-12-14 03:43:24

问题


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

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:

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.


回答1:


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”?

But this is a great article.

Here you can find a solution to your problem.




回答2:


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



来源:https://stackoverflow.com/questions/14340519/html-input-file-how-to-translate-choose-file-and-no-file-chosen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!