From 63453a6a69896bf29ddf89680bc2210b794a9b93 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 18 Jan 2024 11:40:44 -0500 Subject: [PATCH] Rosetta: Enable locale-specific customizations to theme.json settings. (#120) Rosetta: Enable locale-specific customizations to theme.json settings, eg font sizes. --- .../themes/wporg-parent-2021/functions.php | 1 + .../wporg-parent-2021/inc/rosetta-styles.php | 92 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 source/wp-content/themes/wporg-parent-2021/inc/rosetta-styles.php diff --git a/source/wp-content/themes/wporg-parent-2021/functions.php b/source/wp-content/themes/wporg-parent-2021/functions.php index 95f83f0e..71a516c8 100644 --- a/source/wp-content/themes/wporg-parent-2021/functions.php +++ b/source/wp-content/themes/wporg-parent-2021/functions.php @@ -8,6 +8,7 @@ require_once __DIR__ . '/inc/gutenberg-tweaks.php'; require_once __DIR__ . '/inc/block-styles.php'; +require_once __DIR__ . '/inc/rosetta-styles.php'; /** * Actions and filters. diff --git a/source/wp-content/themes/wporg-parent-2021/inc/rosetta-styles.php b/source/wp-content/themes/wporg-parent-2021/inc/rosetta-styles.php new file mode 100644 index 00000000..f154481a --- /dev/null +++ b/source/wp-content/themes/wporg-parent-2021/inc/rosetta-styles.php @@ -0,0 +1,92 @@ + 2, + 'settings' => $locale_settings, + ); + + return new \WP_Theme_JSON( $config, 'custom' ); +} + +/** + * Get a theme.json-shaped array with custom values for a given locale. + * + * The returned array should match the structure of "settings" in a theme.json + * file. These will be loaded as the "user" settings, which will override the + * theme.json values. Rosetta sites can then override any of the generated + * custom properties (ex, --wp--preset--font-size--normal) in a way that will + * cascade to any future child themes, and also render correctly in the editor. + * + * @param string $locale The current site locale. + * + * @return array An array of settings mirroring a theme.json "settings" object. + */ +function get_locale_customizations( $locale ) { + switch ( $locale ) { + case 'ca': + case 'fr': + case 'it_IT': + case 'ro_RO': + return [ + 'typography' => [ + 'fontSizes' => [ + [ + 'slug' => 'heading-cta', + 'size' => '96px', + ], + ], + ], + ]; + case 'ja': + return [ + 'custom' => [ + 'heading' => [ + 'cta' => [ + 'breakpoint' => [ + 'small-only' => [ + 'typography' => [ + 'fontSize' => '50px', + ], + ], + ], + ], + ], + ], + 'typography' => [ + 'fontSizes' => [ + [ + 'slug' => 'heading-cta', + 'size' => '96px', + ], + [ + 'slug' => 'heading-2', + 'size' => '40px', + ], + ], + ], + ]; + } + return false; +}