Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RadGH
Created September 23, 2020 04:25
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 RadGH/9be81b29562a9d3c91860cd35e96b404 to your computer and use it in GitHub Desktop.
Save RadGH/9be81b29562a9d3c91860cd35e96b404 to your computer and use it in GitHub Desktop.
Log all gettext strings on a page in wordpress
<?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 );
@RadGH
Copy link
Author

RadGH commented Sep 23, 2020

Output would look like:

PHP Errors in Ajax Response
PHP Fatal Error
Do not track any visits from this device.
%1$s, Author at %2$s
You searched for %s
Page not found
The post %1$s appeared first on %2$s.
Error 404: Page not found
Archives for
Home
You searched for
Dash
En dash
Em dash
Colon
Middle dot
Bullet
Asterisk
Low asterisk
Vertical bar
Small tilde
Left angle quotation mark
Right angle quotation mark
Less than sign
Greater than sign
html_lang_attribute
%1$s %2$s %3$s Comments Feed
%1$s %2$s %3$s Category Feed
%1$s %2$s %3$s Tag Feed
%1$s %2$s %3$s %4$s Feed
%1$s %2$s Posts by %3$s Feed
%1$s %2$s Search Results for “%3$s� Feed
%1$s %2$s %3$s Feed
View cart
This site uses the Open External Links in a New Window plugin v1.4 by WebFactory Ltd.
Download it for free at
To search, type and hit enter.
Search
Custom Link
…
Is %s
User is %s
User
Is logged in
User is logged in
User registration is allowed
Front Page
Page type
Single Post
Page
Is Archive page
Mobile
Device
Is RTL
Language
From country
Continue reading %s
(more…)
Review Form
Previous
Role
Discussion
Please fill in all required fields
Workflow
Entry Link
Entry URL
Inbox Link
Inbox URL
Cancel Link
Cancel URL
Note
Timeline
Assignees
Approve Link
Approve URL
Approve Token
Reject Link
Reject URL
Reject Token
Type to search
Select a User
Please wait for images to finish uploading.
U.S. Dollar
Pound Sterling
Euro
Australian Dollar
Brazilian Real
Canadian Dollar
Czech Koruna
Danish Krone
Hong Kong Dollar
Hungarian Forint
Israeli New Sheqel
Japanese Yen
Malaysian Ringgit
Mexican Peso
Norwegian Krone
New Zealand Dollar
Philippine Peso
Polish Zloty
Russian Ruble
Singapore Dollar
South African Rand
Swedish Krona
Swiss Franc
Taiwan New Dollar
Thai Baht
Step
of
click to duplicate this field
click to delete this field
HTML
Parent Entry ID
Parent Entry Form ID
Child Form Field ID
Hidden
Checkboxes
Email
Enter Email
Confirm Email
Previous Page
Next Page
Next
Radio Buttons
Submit

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