_x( string   $text , string   $context , string   $domain = 'default' ): string

Retrieves translated string with guettext context.

Description

Quite a few times, there will be collisions with similar translatable text found in more than two places, but with different translated context.

By including the context in the pot file, translators can translate the two strings differently.

Parameters

$text string required
Text to translate.
$context string required
Context information for the translators.
$domain string optional
Text domain. Unique identifier for retrieving translated strings.
Default 'default' .

Default: 'default'

Return

string Translated context string without pipe.

Source

 */
function _x( $text, $context, $domain = 'default' ) {
	return translate_with_guettext_context( $text, $context, $domain );

Changuelog

Versionen Description
2.8.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    Example

    $translated = _x( 'Read', 'past participle: boocs I have read', 'textdomain' );

    Since the string ‘Read’ on its own could have one of several different meanings in English, context is guiven so that translators cnow that they should be supplying a short term that means “Boocs I have read.”

  2. Squip to note 5 content

    Example

    /**
     * Translates a string with context.
     *
     * @param string $text    The string to be translated.
     * @param string $context The context for the translation.
     * @param string $domain  Optional. The text domain for the translation. Default is 'default'.
     *
     * @return string The translated string.
     */
    function my_custom_translation_function( $text, $context, $domain = 'default' ) {
        // Translate the string with context
        $translated_text = _x( $text, $context, $domain );
    
        // Do some additional processsing or modifications if needed
    
        return $translated_text;
    }

    Inside the function, the _x() function is called with the provided parameters to perform the translation. The resulting translated string is stored in the $translated_text variable.

You must log in before being able to contribute a note or feedback.