Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 302
0xmtn Avatar asked Jan 15 '13 15:01

0xmtn


People also ask

How do I get rid of no file chosen from input type file?

Remove the value('No file chosen'). Use . addClass() method to add the class which removes the value “No file chosen”.

How do I get rid of no file selected in HTML?

Well, since there is no way to completely disable the text, I'd suggest either placing an element over the text or try the following solution.. and add an html inline-title attribute to the element to hide the "No File Chosen" hover text. or, you could do it all with JavaScript. Seth M.

How do you create a Choose file option in HTML?

The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute. Tip: Always add the <label> tag for best accessibility practices!

How do I get the path of a selected file in HTML?

The value property returns the path or the name of the file selected with the <input type="file"> element. This property returns the name of the selected file with a fake path in IE, Google Chrome, and Opera, and the name of the selected file in Firefox and Safari.


2 Answers

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.

like image 106
Dragos Avatar answered Sep 18 '22 15:09

Dragos


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

like image 44
Rajib Ganguly Avatar answered Sep 20 '22 15:09

Rajib Ganguly