Last active
July 26, 2016 19:18
-
-
Save calvinjuarez/d8e379752b0b671495b6f1b2f689c6ac to your computer and use it in GitHub Desktop.
Font Localization with Preprocessors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// variables.fonts.less | |
// | |
@font-headings: "Some Character-limited Font"; | |
@font-stack: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
// | |
// fonts.less | |
// | |
.font-headings { // Default :extend() base. | |
font-family: @font-headings, @font-stack; | |
} | |
.font(@font-family) { | |
& when (@font-family = headings) { | |
&:extend(.font-headings all); // Using `all` allows for extending nested selectors. | |
} | |
} | |
// | |
// some-component.less | |
// | |
.some-component { | |
.font(headings); | |
} | |
// | |
// l10n.language.less | |
// | |
:lang(ja) { | |
.font-headings { // Localized :extend() base. | |
font-family: @font-stack; // Don't included the character-limited font on the stack. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// variables.fonts.scss | |
// | |
$font-headings: "Some Character-limited Font"; | |
$font-stack: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
// | |
// fonts.scss | |
// | |
.font-headings { // Default @extend base. | |
font-family: $font-headings, $font-stack; | |
} | |
@mixin font($font-family) { | |
@if $font-family == headings { | |
@extend .font-headings; | |
} | |
} | |
// | |
// some-component.scss | |
// | |
.some-component { | |
@include font(headings); | |
} | |
// | |
// l10n.language.scss | |
// | |
:lang(ja) { | |
.font-headings { // Localized @extend base. | |
font-family: $font-stack; // Don't included the character-limited font on the stack. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.font-headings, | |
.some-component { | |
font-family: "Some Character-limited Font", "Helvetica Neue", Helvetica, Arial, sans-serif; | |
} | |
:lang(ja) .font-headings, | |
:lang(ja) .some-component { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment