Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created January 9, 2020 07:03
Show Gist options
  • Save ipokkel/f562c847dfe41763701e2efe12eff647 to your computer and use it in GitHub Desktop.
Save ipokkel/f562c847dfe41763701e2efe12eff647 to your computer and use it in GitHub Desktop.
Translate text that has contexts - This filter hook is applied to the translated text by the internationalization function that handle contexts (_x(), _ex(), esc_attr_x() and esc_html_x()).
<?php // do NOT copy this line, copy from below this line
// Add this code below to your PMPro Customizations plugin
// http://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
/**
* This filter hook is applied to the translated text by the internationalization function that handle contexts (_x(), _ex(), esc_attr_x() and esc_html_x()).
*
* @param string $translated
* @param string $text
* @param string $context
* @param string $domain
* @return string
* @link https://developer.wordpress.org/reference/hooks/gettext_with_context/
*/
function example_gettext_with_context( $translated, $text, $context, $domain ) {
switch ( $domain ) {
case 'plugin-text-domain':
switch ( $text ) {
case 'text to translate':
$translated = 'translated text';
break;
}
break;
}
return $translated;
}
add_filter( 'gettext_with_context', 'example_gettext_with_context', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment