Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/update-fonts-i18n
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: enhancement

Add fonts for better i18n compatibility.
32 changes: 31 additions & 1 deletion projects/plugins/jetpack/modules/google-fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@
'Work Sans',
);

const JETPACK_GOOGLE_FONTS_I18N = array(
'Alexandria' => 'Alexandria (Arabic)',
'IBM Plex Sans Arabic' => 'IBM Plex Sans (Arabic)',
'Noto Sans Hebrew' => 'Noto Sans (Hebrew)',
'Noto Sans HK' => 'Noto Sans (Hong Kong)',
'Noto Sans JP' => 'Noto Sans (Japanese)',
'Noto Sans KR' => 'Noto Sans (Korean)',
'Noto Sans SC' => 'Noto Sans (Simplified Chinese)',
'Noto Sans TC' => 'Noto Sans (Traditional Chinese)',
'Noto Sans Telugu' => 'Noto Sans (Telugu)',
'Noto Serif Hebrew' => 'Noto Serif (Hebrew)',
'Noto Serif HK' => 'Noto Serif (Hong Kong)',
'Noto Serif JP' => 'Noto Serif (Japanese)',
'Noto Serif KR' => 'Noto Serif (Korean)',
'Noto Serif SC' => 'Noto Serif (Simplified Chinese)',
'Noto Serif TC' => 'Noto Serif (Traditional Chinese)',
);

/**
* Register a curated selection of Google Fonts.
*
Expand All @@ -68,6 +86,9 @@ function jetpack_add_google_fonts_provider() {

wp_register_webfont_provider( 'jetpack-google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' );

// Ensure i18n specific fonts are at the end of the list
$fonts_list = array_merge( JETPACK_GOOGLE_FONTS_LIST, array_keys( JETPACK_GOOGLE_FONTS_I18N ) );

/**
* Curated list of Google Fonts.
*
Expand All @@ -77,19 +98,28 @@ function jetpack_add_google_fonts_provider() {
*
* @param array $fonts_to_register Array of Google Font names to register.
*/
$fonts_to_register = apply_filters( 'jetpack_google_fonts_list', JETPACK_GOOGLE_FONTS_LIST );
$fonts_to_register = apply_filters( 'jetpack_google_fonts_list', $fonts_list );

foreach ( $fonts_to_register as $font_family ) {

$font_name = $font_family;

if ( array_key_exists( $font_family, JETPACK_GOOGLE_FONTS_I18N ) ) {
$font_name = JETPACK_GOOGLE_FONTS_I18N[ $font_family ];
}

wp_register_webfonts(
array(
array(
'name' => $font_name,
'font-family' => $font_family,
'font-weight' => '100 900',
'font-style' => 'normal',
'font-display' => 'fallback',
'provider' => 'jetpack-google-fonts',
),
array(
'name' => $font_name,
'font-family' => $font_family,
'font-weight' => '100 900',
'font-style' => 'italic',
Expand Down