Last active
December 21, 2015 00:19
-
-
Save glueckpress/6219706 to your computer and use it in GitHub Desktop.
[WordPress] Modify default (not translated) language strings of a plugin. Beware: Might result in performance issues when applied to many strings.
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 | |
/** | |
* Translate text strings in WordPress programmatically. | |
* | |
* Assuming plugin intorduces "Foo_Plugin" class, has text domain "foo-plugin". | |
* | |
* @param mixed $translated | |
* @param mixed $original | |
* @param mixed $domain | |
* @return string | |
*/ | |
function gp1410201916( $translated, $original, $domain ) { | |
/* Only strings from given plugin */ | |
if( ! class_exists( 'Foo_Plugin' ) || 'foo-plugin' !== $domain ) { | |
return $translated; | |
} | |
/* 'Original string' => 'New string' */ | |
$strings = array( 'Wordpress' => 'WordPress' ); | |
if( isset( $strings[ $original ] ) ) { | |
$translations = &get_translations_for_domain( $domain ); | |
$translated = $translations->translate( $strings[$original] ); | |
} | |
return $translated; | |
} | |
add_filter( 'gettext', 'gp1410201916', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment