Skip to content

Commit

Permalink
Rosetta: Add 'palt' font setting for Japanese sites
Browse files Browse the repository at this point in the history
Fixes #145
  • Loading branch information
ryelle committed Aug 2, 2024
1 parent e8c2e50 commit 9f39020
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions source/wp-content/themes/wporg-parent-2021/inc/rosetta-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@
* @return WP_Theme_JSON_Data The updated user settings.
*/
function inject_i18n_customizations( $theme_json ) {
$locale_settings = get_locale_customizations( get_locale() );
if ( ! $locale_settings ) {
$locale_settings = get_locale_settings( get_locale() );
$locale_styles = get_locale_styles( get_locale() );
if ( ! $locale_settings && ! $locale_styles ) {
return $theme_json;
}

$config = array(
'version' => 2,
'settings' => $locale_settings,
);

return new \WP_Theme_JSON_Data( $config, 'custom' );
if ( $locale_settings ) {
$config['settings'] = $locale_settings;
}

if ( $locale_styles ) {
$config['styles'] = $locale_styles;
}

return $theme_json->update_with( $config, 'custom' );
}

/**
Expand All @@ -43,7 +51,7 @@ function inject_i18n_customizations( $theme_json ) {
*
* @return array An array of settings mirroring a theme.json "settings" object.
*/
function get_locale_customizations( $locale ) {
function get_locale_settings( $locale ) {
switch ( $locale ) {
case 'ca':
case 'fr_FR':
Expand Down Expand Up @@ -104,3 +112,23 @@ function get_locale_customizations( $locale ) {
}
return false;
}

/**
* Get a theme.json-shaped array with custom values for a given locale.
*
* The returned array should match the structure of "styles" in a theme.json
* file. This can be used to override block, element, and sitewide styles.
* The `css` key can also be used to inject CSS code into all child themes.
*
* @param string $locale The current site locale.
*
* @return array An array of styles mirroring a theme.json "styles" object.
*/
function get_locale_styles( $locale ) {
switch ( $locale ) {
case 'ja':
return [
'css' => 'body { font-feature-settings: "palt"; }',
];
}
}

0 comments on commit 9f39020

Please sign in to comment.