Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active February 7, 2017 14:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save joshfeck/4962940 to your computer and use it in GitHub Desktop.
Save joshfeck/4962940 to your computer and use it in GitHub Desktop.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function mycustom_filter_gettext( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'Register' => 'Sign up',
'Confirm and go to payment page' => 'Complete registration',
'No events available...' => 'No upcoming classes at this time...',
'click here to add a new state/province' => 'click here to enter address outside US/Canada',
// 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 __()
// but without running it through the filter again
$translations = get_translations_for_domain( $domain );
$translated = $translations->translate( $strings[$original] );
}
return $translated;
}
add_filter( 'gettext', 'mycustom_filter_gettext', 10, 3 );
@eivind1984
Copy link

Just a little heads up to peple running non-english installations: The strings in the $strings array needs to be the original english string, not the one that's already being translated. So, in my case, I wanted to change the phrase "Tilgjengelige billetter", but still had to put "Available tickets" in the $strings array to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment