Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created July 12, 2018 22:15
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 Pebblo/de0b054ecaeb7d333ca1b823f2b02efa to your computer and use it in GitHub Desktop.
Save Pebblo/de0b054ecaeb7d333ca1b823f2b02efa to your computer and use it in GitHub Desktop.
<?php //Please do not include the opening PHP tag if you alreaddy have one
function mycustom_filter_gettext_with_context( $translated, $original, $context, $domain ) {
if( $domain === 'event_espresso' ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'Attendee %d' => 'Participant %d',
// Add some more strings here
);
// See if the current string is in the $strings array
// If so, replace its translation
if ( isset( $strings[$original] ) ) {
// This accomplishes the same thing as _x()
// but without running it through the filter again
$translations = get_translations_for_domain( $domain );
$translated = $translations->translate( $strings[$original], $context, $domain );
}
}
return $translated;
}
add_filter( 'gettext_with_context', 'mycustom_filter_gettext_with_context', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment