Created
January 9, 2020 07:03
-
-
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()).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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