Languages: English • 日本語 Русский • (Add your language)
Retrieves the translated string from the translate().
<?php $translated_text = __( $text, $domain ); ?>
Make a string inside your plugin or theme translatable:
$translated = __( 'Hello World!', 'mytextdomain' );
'mytextdomain' needs to be a unique text domain used throughout your plugin/theme. This should always be directly passed as a string literal as shown above, not a string assigned to a variable or constant. E.g., this is incorrect:
// ----- > so, such method is incorrect $text_domain = 'mytextdomain'; $string = 'Hello World!'; $translated = __( $string, $text_domain );
This seems to work, but it will interfere in automatic parsing of your plugin/theme's files for translation. See these for more information:
-- If you want to manually change translation for that string using a hook, then use:
add_filter( 'gettext', 'my_changerr', 20, 3 ); function my_changerr( $translated_text, $text, $domain ) { if ( is_singular() ) { switch ( $translated_text ) { case 'Hello World!' : $translated_text = __( 'hiiiiiiii!', 'your_new_text_domain' ); break; } } return $translated_text; }
in this case, __( 'Hello World!', 'mytextdomain' ) returns hiiiiiiii!
__() is located in wp-includes/l10n.php
.
L10n: translate(), __(), _e(), _n(), _x(), _ex(), _nx(), esc_attr__(), esc_attr_e(), esc_attr_x(), esc_html__(), esc_html_e(), esc_html_x(), _n_noop(), _nx_noop(), translate_nooped_plural()