Last active
December 14, 2015 21:31
-
-
Save glueckpress/ec9a10bdec49d5e2e9a1 to your computer and use it in GitHub Desktop.
[WordPress] Exclude text domains from language files by wrapping them into custom functions instead of default l10n functions. (http://glck.be/6651/)
This file contains hidden or 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 | |
/* String from your theme/plugin */ | |
_e( 'Margaritas!', 'your-textdomain' ); | |
__( 'Margaritas!', 'your-textdomain' ); | |
/* Original string from WooCommerce: */ | |
_e( 'Product', 'woocommerce' ); | |
__( 'Product', 'woocommerce' ); |
This file contains hidden or 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 | |
/* In your own theme/plugin replace with: */ | |
wcl10n_e( 'Product', 'woocommerce' ); | |
wcl10n__( 'Product', 'woocommerce' ); |
This file contains hidden or 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 | |
/** | |
* Wrappers for default l10n functions to include in your theme or plugin. | |
*/ | |
if ( ! function_exists( 'wcl10n__' ) ) { | |
/** | |
* Wrapper for __() gettext function. | |
* @param string $string Translatable text string | |
* @param string $textdomain Text domain, default: woocommerce | |
* @return void | |
*/ | |
function wcl10n__( $string, $textdomain = 'woocommerce' ) { | |
return __( $string, $textdomain ); | |
} | |
} | |
if ( ! function_exists( 'wcl10n_e' ) ) { | |
/** | |
* Wrapper for _e() gettext function. | |
* @param string $string Translatable text string | |
* @param string $textdomain Text domain, default: woocommerce | |
* @return void | |
*/ | |
function wcl10n_e( $string, $textdomain = 'woocommerce' ) { | |
echo __( $string, $textdomain ); | |
} | |
} | |
/* repeat for other l10n function, see wp-includes/l10n.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
_e
function in WordPress echoes the string, so you can't return it. This means your second example here doesn't quite work as expected. Useecho __( $string, $textdomain )
instead.