Skip to content

Commit

Permalink
Only format the string if tokens are present.
Browse files Browse the repository at this point in the history
  • Loading branch information
jffng committed Sep 10, 2024
1 parent a9ca35a commit 0460dc5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions includes/create-theme/theme-locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,22 @@ private static function escape_text_content( $string ) {
$text .= esc_html( $p->get_modifiable_text() );
}
}
// If tokens is not empty, format the string using sprintf.
if ( ! empty( $tokens ) ) {
// Format the string, replacing the placeholders with the formatted tokens.
return "<?php\n/* Translators: %s are html tags */\necho sprintf( esc_html__( '$text', '" . wp_get_theme()->get( 'TextDomain' ) . "' ), " . implode(
', ',
array_map(
function( $token ) {
return "'$token'";
},
$tokens
)
) . '); ?>';
}

return "<?php esc_html_e('" . $string . "', '" . wp_get_theme()->get( 'TextDomain' ) . "');?>";

// Format the string, replacing the placeholders with the formatted tokens.
$mystring = "<?php\n/* Translators: %s are html tags */\necho sprintf( esc_html__( '$text', '" . wp_get_theme()->get( 'TextDomain' ) . "' ), " . implode(
', ',
array_map(
function( $token ) {
return "'$token'";
},
$tokens
)
) . '); ?>';

return $mystring;
}

/**
Expand Down

0 comments on commit 0460dc5

Please sign in to comment.