Skip to content

Instantly share code, notes, and snippets.

@calvinjuarez
Last active July 26, 2016 19:18
Show Gist options
  • Save calvinjuarez/d8e379752b0b671495b6f1b2f689c6ac to your computer and use it in GitHub Desktop.
Save calvinjuarez/d8e379752b0b671495b6f1b2f689c6ac to your computer and use it in GitHub Desktop.
Font Localization with Preprocessors
//
// 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.
}
}
//
// 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.
}
}
.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