Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Fonts: Language selection not working [duplicate]

I am using the Google Font Roboto on quite a few client websites.

When you are customising the font on Google Fonts you have many language options to pick from:

  • Greek (Supported by Roboto)
  • Latin Extended (Supported by Roboto)
  • Cyrillic (Supported by Roboto)
  • Vietnamese (Supported by Roboto)
  • Cyrillic Extended (Supported by Roboto)
  • Greek Extended (Supported by Roboto)
  • Latin (Supported by all Fonts)

For these client sites, I only need to use the Latin language, and don't need to load in any other languages.

However, when I load this font in and the Latin language defined, you can see all the other languages are also loaded in the generated stylesheet:

https://fonts.googleapis.com/css?family=Roboto:300&subset=latin

/* cyrillic-ext */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/0eC6fl06luXEYWpBSJvXCBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
/* cyrillic */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* greek-ext */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/-L14Jk06m6pUHB-5mXQQnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+1F00-1FFF;
}
/* greek */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/I3S1wsgSg9YCurV6PUkTORJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0370-03FF;
}
/* vietnamese */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/NYDWBdD4gIq26G5XYbHsFBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Pru33qjShpZSmG3z6VYwnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}

It was my understanding that defining &subset=latin loads in only that language, so why are all the languages being loaded in here?

like image 877
Jamie Wade Avatar asked Nov 07 '16 10:11

Jamie Wade


People also ask

Which Google font supports all languages?

Well, Google Noto is here to remedy that. Taking its name from its goal to see 'no more tofu', Google Noto is a font which aims to 'support all languages with a harmonious look and feel'. The core Noto Sans font supports up to 582 languages across 237 regions, and even comes in 72 styles.

Are Google Fonts GDPR compliant?

The German court found that the embedding of Google Fonts on a website violates GDPR because such use of Google Fonts does not comply with any of the legal bases that can be used for processing personal data.

How do I use Google Fonts in HTML and CSS?

To add google fonts, search for the google fonts, select the font category and family, then select the font style of your choice. Once you select the font, “copy the font link”, from the “selected families windows” and paste it in the head section of the HTML file.


1 Answers

I am copying this answer by Daryl Teo as he seems to provide the correct answer to your question.

The trick lies with this optimization:

unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;

With this, the browser knows whether it needs to download the font, depending on the characters it just loaded in the html.

See here which browsers have full support for this.

Earlier browsers, e.g., Firefox < 44 and Safari < 10, ignored (parts) of the spec, or it needed to be enabled, therefore Google Fonts has to serve it a minimal font-face specification.

like image 87
Frederik Krautwald Avatar answered Sep 21 '22 16:09

Frederik Krautwald