Created
September 23, 2020 04:25
-
-
Save RadGH/9be81b29562a9d3c91860cd35e96b404 to your computer and use it in GitHub Desktop.
Log all gettext strings on a page in wordpress
This file contains 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 | |
function log_gettext_string( $text ) { | |
global $mylist; | |
if ( !isset($mylist) ) { | |
$mylist = array(); | |
register_shutdown_function(function($a = null) { global $mylist; echo implode('<br>', $mylist); exit; } ); | |
} | |
$mylist[$text] = $text; | |
} | |
// __( "hello world" ) | |
function show_all_gettext_strings( $translated_text, $text, $domain ) { | |
log_gettext_string( $text ); | |
return $translated_text; | |
} | |
add_filter( 'gettext', 'show_all_gettext_strings', 10, 4 ); | |
// _n( "hello %d world", "hello %d worlds", $number_of_worlds ) | |
function show_all_gettext_strings__n( $translation, $single, $plural, $number, $domain ) { | |
log_gettext_string( $single ); | |
log_gettext_string( $plural ); | |
return $translation; | |
} | |
add_filter( 'ngettext', 'show_all_gettext_strings__n', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output would look like: