WordPress.org

Ready to get started?Download WordPress

Codex

Plugin API/Filter Reference/gettext with context

Contents

Description

This filter hook is applied to the translated text by context-specific localization functions such as such as _x(). The filter is always applied even if localization is not in effect, and if the text domain has not been loaded.

For context-unspecific translation functions such as __(), see filter hook gettext.

Arguments

Filter function arguments are: 'translated text', 'untranslated text', 'context, and 'text domain'. apply_filters( 'gettext_with_context', $translated, $text, $context, $domain );

The text domain for WordPress translatable texts is 'default'.

Examples

/**
* @param string $translated
* @param string $text
* @param string $context
* @param string $domain
* @return string
*/
function example_gettext_with_context( $translated, $text, $context, $domain ) {
    if ( 'example-plugin' == $domain ) {
        if ( 'directions' == $text && 'directions on map' == $directions ) {
            $translated = 'map directions';  // not recipe instructions!
        }
    }

    return $translated;
}
add_filter( 'gettext_with_context', 'example_gettext_with_context' );

Related