Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created January 12, 2016 11:26
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/ccd094b53386448edcf6 to your computer and use it in GitHub Desktop.
Save Pebblo/ccd094b53386448edcf6 to your computer and use it in GitHub Desktop.
Example of translating strings within EE4.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function mycustom_filter_gettext_new( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'This option allows you to use the above information for all additional attendee question fields. %sPlease note:%s some events may have additional questions that you may still be required to answer in order to complete your registration.' => 'TONY1',
'%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.' => 'CONGRATS TONY MESSAGE',
// 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_new', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment