Skip to content

Commit 696c407

Browse files
MartijnCuppensXhmikosR
authored andcommitted
Customize browse text of the custom file input with HTML (#27651)
1 parent dafb498 commit 696c407

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

scss/_custom-forms.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@
276276
content: $value;
277277
}
278278
}
279+
280+
~ .custom-file-label[data-browse]::after {
281+
content: attr(data-browse);
282+
}
279283
}
280284

281285
.custom-file-label {

site/docs/4.1/components/forms.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ The file input is the most gnarly of the bunch and requires additional JavaScrip
12871287

12881288
We hide the default file `<input>` via `opacity` and instead style the `<label>`. The button is generated and positioned with `::after`. Lastly, we declare a `width` and `height` on the `<input>` for proper spacing for surrounding content.
12891289

1290-
#### Translating or customizing the strings
1290+
#### Translating or customizing the strings with SCSS
12911291

12921292
The [`:lang()` pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:lang) is used to allow for translation of the "Browse" text into other languages. Override or add entries to the `$custom-file-text` Sass variable with the relevant [language tag](https://en.wikipedia.org/wiki/IETF_language_tag) and localized strings. The English strings can be customized the same way. For example, here's how one might add a Spanish translation (Spanish's language code is `es`):
12931293

@@ -1309,3 +1309,15 @@ Here's `lang(es)` in action on the custom file input for a Spanish translation:
13091309
{% include example.html content=example %}
13101310

13111311
You'll need to set the language of your document (or subtree thereof) correctly in order for the correct text to be shown. This can be done using [the `lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang) on the `<html>` element or the [`Content-Language` HTTP header](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12), among other methods.
1312+
1313+
#### Translating or customizing the strings with HTML
1314+
1315+
Bootstrap also provides a way to translate the "Browse" text in HTML with the `data-browse` attribute which can be added to the custom input label (example in Dutch):
1316+
1317+
{% capture example %}
1318+
<div class="custom-file">
1319+
<input type="file" class="custom-file-input" id="customFileLangHTML">
1320+
<label class="custom-file-label" for="customFileLangHTML" data-browse="Bestand kiezen">Voeg je document toe</label>
1321+
</div>
1322+
{% endcapture %}
1323+
{% include example.html content=example %}

0 commit comments

Comments
 (0)