Locale-specific CSS & Fonts¶
Out of date
This section needs updating to reflect our current font usage. But the techniques remain valid.
If a localized page needs some locale-specific style tweaks, you can add the style rules to the page's stylesheet like this:
If a locale needs site-wide style tweaks, font settings in particular, you can add the rules to /media/css/l10n/{{LANG}}/intl.css. Pages on Bedrock automatically includes the CSS in the base templates with the l10n_css helper function. The CSS may also be loaded directly from other Mozilla sites with such a URL: //mozorg.cdn.mozilla.net/media/css/l10n/{{LANG}}/intl.css.
Custom Fonts¶
Open Sans, the default font on mozilla.org, doesn't offer non-Latin glyphs. intl.css can have @font-face rules to define locale-specific fonts using custom font families as below:
- X-LocaleSpecific-Light: Used in combination with Open Sans Light. The font can come in 2 weights: normal and optionally bold
- X-LocaleSpecific: Used in combination with Open Sans Regular. The font can come in 2 weights: normal and optionally bold
- X-LocaleSpecific-Extrabold: Used in combination with Open Sans Extrabold. The font weight is 800 only
Here's an example of intl.css:
@font-face {
font-family: X-LocaleSpecific-Light;
font-weight: normal;
font-display: swap;
src: local(mplus-2p-light), local(Meiryo);
}
@font-face {
font-family: X-LocaleSpecific-Light;
font-weight: bold;
font-display: swap;
src: local(mplus-2p-medium), local(Meiryo-Bold);
}
@font-face {
font-family: X-LocaleSpecific;
font-weight: normal;
font-display: swap;
src: local(mplus-2p-regular), local(Meiryo);
}
@font-face {
font-family: X-LocaleSpecific;
font-weight: bold;
font-display: swap;
src: local(mplus-2p-bold), local(Meiryo-Bold);
}
@font-face {
font-family: X-LocaleSpecific-Extrabold;
font-weight: 800;
font-display: swap;
src: local(mplus-2p-black), local(Meiryo-Bold);
}
Specifying Fonts¶
Localizers can specify locale-specific fonts in one of the following ways:
- Choose best-looking fonts widely used on major platforms, and specify those with the
src: local(name)syntax - Find a best-looking free Web font, add the font files to
/media/fonts/, and specify those with thesrc: url(path)syntax - Create a custom Web font to complement missing glyphs in Open Sans, add the font files to
/media/fonts/l10n/, and specify those with thesrc: url(path)syntax. M+ 2c offers various international glyphs and looks similar to Open Sans, while Noto Sans is good for the bold and italic variants. You can create subsets of these alternative fonts in the WOFF and WOFF2 formats using a tool found on the Web. See Bug 1360812 for the Fulah (ff) locale's example
Using the Font Mixins¶
Developers should use the .open-sans mixin instead of font-family: 'Open Sans' to specify the default font family in CSS. This mixin has both Open Sans and X-LocaleSpecific so locale-specific fonts, if defined, will be applied to localized pages. The variant mixins, .open-sans-light and .open-sans-extrabold, are also available.