aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Cuppens <[email protected]>2018-11-13 07:30:17 +0100
committerXhmikosR <[email protected]>2018-11-13 08:30:17 +0200
commit696c4078d1318ec28ddada227449a4acaf52dee7 (patch)
tree9f713974e0cbc97b94af3da7e7cec6f4b6251635
parentdafb498f75afe2552b8603ac59fe855b488a97e8 (diff)
downloadbootstrap-696c4078d1318ec28ddada227449a4acaf52dee7.tar.xz
bootstrap-696c4078d1318ec28ddada227449a4acaf52dee7.zip
Customize browse text of the custom file input with HTML (#27651)
-rw-r--r--scss/_custom-forms.scss4
-rw-r--r--site/docs/4.1/components/forms.md14
2 files changed, 17 insertions, 1 deletions
diff --git a/scss/_custom-forms.scss b/scss/_custom-forms.scss
index 9088662fd..e999daf0c 100644
--- a/scss/_custom-forms.scss
+++ b/scss/_custom-forms.scss
@@ -276,6 +276,10 @@
content: $value;
}
}
+
+ ~ .custom-file-label[data-browse]::after {
+ content: attr(data-browse);
+ }
}
.custom-file-label {
diff --git a/site/docs/4.1/components/forms.md b/site/docs/4.1/components/forms.md
index 64ec2cea2..29f7fc10b 100644
--- a/site/docs/4.1/components/forms.md
+++ b/site/docs/4.1/components/forms.md
@@ -1287,7 +1287,7 @@ The file input is the most gnarly of the bunch and requires additional JavaScrip
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.
-#### Translating or customizing the strings
+#### Translating or customizing the strings with SCSS
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`):
@@ -1309,3 +1309,15 @@ Here's `lang(es)` in action on the custom file input for a Spanish translation:
{% include example.html content=example %}
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.
+
+#### Translating or customizing the strings with HTML
+
+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):
+
+{% capture example %}
+<div class="custom-file">
+ <input type="file" class="custom-file-input" id="customFileLangHTML">
+ <label class="custom-file-label" for="customFileLangHTML" data-browse="Bestand kiezen">Voeg je document toe</label>
+</div>
+{% endcapture %}
+{% include example.html content=example %}