aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2016-02-09 01:38:14 -0800
committerChris Rebert <[email protected]>2016-02-09 01:38:14 -0800
commita1bf344c4f041ad88acaf5b2b3777c733d3afe40 (patch)
tree038a730f2a6d06913b02dc33cba9e72346a1c8b3
parenta263e194194969fa0daf5fde938a330f6c77be81 (diff)
parentaa62428cdf574cd42c105d966e7153dd69d80101 (diff)
downloadbootstrap-a1bf344c4f041ad88acaf5b2b3777c733d3afe40.tar.xz
bootstrap-a1bf344c4f041ad88acaf5b2b3777c733d3afe40.zip
Merge pull request #18925 from twbs/fixes-18922
Make translation of custom file input text easier
-rw-r--r--docs/components/forms.md19
-rw-r--r--scss/_custom-forms.scss13
-rw-r--r--scss/_variables.scss10
3 files changed, 37 insertions, 5 deletions
diff --git a/docs/components/forms.md b/docs/components/forms.md
index 134bd88c1..17fa953fc 100644
--- a/docs/components/forms.md
+++ b/docs/components/forms.md
@@ -817,3 +817,22 @@ Here's how it works:
- We declare a `height` on the `<input>` for proper spacing for surrounding content.
In other words, it's an entirely custom element, all generated via CSS.
+
+#### Translating or customizing the strings
+
+The [`:lang()` pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:lang) is used to allow for easy translation of the "Browse" and "Choose file..." text into other languages. Simply override or add entries to the `$custom-file-text` SCSS 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`):
+
+{% highlight scss %}
+$custom-file-text: (
+ placeholder: (
+ en: "Choose file...",
+ es: "Seleccionar archivo..."
+ ),
+ button-label: (
+ en: "Browse",
+ es: "Navegar"
+ )
+);
+{% endhighlight %}
+
+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) or the [`Content-Language` HTTP header](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12), among other methods.
diff --git a/scss/_custom-forms.scss b/scss/_custom-forms.scss
index dbb32d42e..1c929e2c3 100644
--- a/scss/_custom-forms.scss
+++ b/scss/_custom-forms.scss
@@ -218,8 +218,10 @@
@include border-radius($custom-file-border-radius);
@include box-shadow($custom-file-box-shadow);
- &::after {
- content: $custom-file-placeholder;
+ @each $lang, $text in map-get($custom-file-text, placeholder) {
+ &:lang(#{$lang})::after {
+ content: $text;
+ }
}
&::before {
@@ -233,9 +235,14 @@
padding: $custom-file-padding-x $custom-file-padding-y;
line-height: $custom-file-line-height;
color: $custom-file-button-color;
- content: $custom-file-button-label;
background-color: $custom-file-button-bg;
border: $custom-file-border-width solid $custom-file-border-color;
@include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
}
+
+ @each $lang, $text in map-get($custom-file-text, button-label) {
+ &:lang(#{$lang})::before {
+ content: $text;
+ }
+ }
}
diff --git a/scss/_variables.scss b/scss/_variables.scss
index 514214814..1d7c67004 100644
--- a/scss/_variables.scss
+++ b/scss/_variables.scss
@@ -404,10 +404,16 @@ $custom-file-border-width: $border-width !default;
$custom-file-border-color: #ddd !default;
$custom-file-border-radius: $border-radius !default;
$custom-file-box-shadow: inset 0 .2rem .4rem rgba(0,0,0,.05) !default;
-$custom-file-placeholder: "Choose file..." !default;
-$custom-file-button-label: "Browse" !default;
$custom-file-button-color: $custom-file-color !default;
$custom-file-button-bg: #eee !default;
+$custom-file-text: (
+ placeholder: (
+ en: "Choose file..."
+ ),
+ button-label: (
+ en: "Browse"
+ )
+) !default;
// Form validation icons