Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate pattern metadata (title & description) #40047

Merged
merged 5 commits into from
Apr 6, 2022
Merged
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
24 changes: 20 additions & 4 deletions lib/compat/wordpress-6.0/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,17 @@ function gutenberg_register_theme_block_patterns() {
);

// Register patterns for the active theme. If the theme is a child theme,
// let it override any patterns from the parent theme that shares the same
// slug.
foreach ( wp_get_active_and_valid_themes() as $theme ) {
$dirpath = $theme . '/patterns/';
// let it override any patterns from the parent theme that shares the same slug.
$themes = array();
$stylesheet = get_stylesheet();
$template = get_template();
if ( $stylesheet !== $template ) {
$themes[] = wp_get_theme( $stylesheet );
}
$themes[] = wp_get_theme( $template );

foreach ( $themes as $theme ) {
$dirpath = $theme->get_stylesheet_directory() . '/patterns/';
if ( file_exists( $dirpath ) ) {
$files = glob( $dirpath . '*.php' );
if ( $files ) {
Expand Down Expand Up @@ -171,6 +178,15 @@ function gutenberg_register_theme_block_patterns() {
}
}

// Translate the pattern metadata.
$text_domain = $theme->get( 'TextDomain' );
//phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.NonSingularStringLiteralContext, WordPress.WP.I18n.NonSingularStringLiteralDomain, WordPress.WP.I18n.LowLevelTranslationFunction
$pattern_data['title'] = translate_with_gettext_context( $pattern_data['title'], 'Pattern title', $text_domain );
if ( ! empty( $pattern_data['description'] ) ) {
//phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.NonSingularStringLiteralContext, WordPress.WP.I18n.NonSingularStringLiteralDomain, WordPress.WP.I18n.LowLevelTranslationFunction
$pattern_data['description'] = translate_with_gettext_context( $pattern_data['description'], 'Pattern description', $text_domain );
}

// The actual pattern content is the output of the file.
ob_start();
include $file;
Expand Down