Skip to content

Instantly share code, notes, and snippets.

@jrfnl
Last active June 14, 2018 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrfnl/24410c92e108ecdb2dca55ed23515361 to your computer and use it in GitHub Desktop.
Save jrfnl/24410c92e108ecdb2dca55ed23515361 to your computer and use it in GitHub Desktop.
201805 WCEU Code samples
<?php
/*
* Example of translators comment for a text string with a single placeholder.
*/
/* translators: %s: the version number of a WordPress release. */
esc_html_e( 'Wordpress %s is awesome!' );
/*
* Example of translators comment for a text string with multiple numbered placeholders.
*/
/* translators: 1: the version number of the current WordPress release; 2: the version number which will come after that. */
esc_html_e( 'Wordpress %1$s is awesome! and %2$s will be even better' );
/*
* Example of INCORRECTLY placed translators comment.
*/
/* translators: %s is the version number of a WordPress release. */
echo '<h2>' . sprintf(
esc_html__( 'Some translatable text with %s placeholder' ), $replacement
);
/*
* Example of CORRECTLY placed translators comment.
*/
echo '<h2>' . sprintf(
/* translators: %s is the version number of a WordPress release. */
esc_html__( 'Some translatable text with %s placeholder' ),
$replacement
);
/*
* Examples of CORRECTLY placed translators comment and code layout when dealing with embedded PHP.
*/
<?php /* translators: %s is the version number of a WordPress release. */ ?>
<h2> <?php printf( esc_html__( 'Some translatable text with %s placeholder' ), $replacement ); ?></h2>
<!-- Alternative code layouts: -->
<?php
/* translators: %s is the version number of a WordPress release. */
$text = sprintf( __( 'Some translatable text with %s placeholder' ), $replacement );
?>
<h2> <?php echo esc_html( $text ); ?></h2>
<h2>
<?php
printf(
/* translators: %s is the version number of a WordPress release. */
esc_html__( 'Some translatable text with %s placeholder' ),
$replacement
);
?>
</h2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment