Translatepress output compatibility

From Lonsdale201/wp-agent-skills · View interactive version

Translatepress output compatibility is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Audit or implement WordPress plugin/theme output so TranslatePress can translate it correctly. Use when code must be compatible with TranslatePress visual translation, gettext string translation, dynamic JS-inserted text, automatic translation exclusions, AJAX/REST-rendered fragments, language-aware

How to use this skill

Skill file

TranslatePress Output Compatibility

TranslatePress translates the rendered front-end page, plus gettext strings and dynamic strings it can detect. Build plugin/theme output as stable, accessible, server-rendered HTML first; then add explicit exclusions only for values that must never be translated.

When to use this skill

Trigger when ANY of the following is true:

Baseline checks

Verify the installed stack before debugging compatibility:

wp plugin list --fields=name,status,version | grep -E 'translatepress'
wp eval 'echo defined( "TRP_PLUGIN_VERSION" ) ? TRP_PLUGIN_VERSION : "missing-core";'
wp option get trp_settings --format=json
wp option get trp_add_ons_settings --format=json

TranslatePress Multilingual 3.2.1 and Business 1.8.2 are the validated versions for this skill. The Business loader blocks TranslatePress when the core version is below 2.8.7, shows a settings-redesign notice below 2.9.7, and loads add-ons from trp_add_ons_settings.

Make text discoverable

Render translatable text as real front-end text, not as opaque data:

printf(
    '<p class="myplugin-status">%s</p>',
    esc_html__( 'Your booking is confirmed.', 'myplugin' )
);

Use normal WordPress i18n functions for plugin/theme UI strings. TranslatePress can translate gettext strings, and site owners may also choose to disable TranslatePress gettext translation so .po/.mo files handle them.

For user-configured copy stored in options, output the saved text plainly:

$message = get_option( 'myplugin_checkout_message', '' );

if ( $message !== '' ) {
    echo wp_kses_post( wpautop( $message ) );
}

Do not store per-language copies in your own option unless the product explicitly owns a multilingual content model. Let TranslatePress translate rendered output.

Dynamic JS output

TranslatePress can detect client-side changes, but do not make it guess around unstable markup:

Language-aware cache key pattern:

$language = isset( $GLOBALS['TRP_LANGUAGE'] ) ? (string) $GLOBALS['TRP_LANGUAGE'] : get_locale();
$cache_key = 'myplugin_card_' . md5( $language . '|' . wp_json_encode( $args ) );

Never cache translated front-end HTML globally without varying by language and, when Different Domain per Language is active, by host.

Exclude text deliberately

Use exclusion attributes only for strings that should remain literal:

echo '<code data-no-translation>' . esc_html( $license_key_mask ) . '</code>';
echo '<span data-no-auto-translation>' . esc_html( $brand_name ) . '</span>';
echo '<div data-no-dynamic-translation id="myplugin-live-clock"></div>';

Meanings:

| Attribute | Use for |

|---|---|

| data-no-translation | Never translate this element or its children. |

| data-no-auto-translation | Allow manual handling, but exclude from automatic translation. |

| data-no-dynamic-translation | Skip JS dynamic detection while still allowing server-side translation when possible. |

| data-no-translation-href | Prevent TranslatePress from translating a specific link URL. |

Programmatic selector exclusions:

add_filter( 'trp_no_translate_selectors', static function ( array $selectors, string $language ): array {
    $selectors[] = '.myplugin-code-sample';
    return $selectors;
}, 10, 2 );

add_filter( 'trp_skip_selectors_from_dynamic_translation', static function ( array $selectors ): array {
    $selectors[] = '.myplugin-live-region';
    return $selectors;
} );

add_filter( 'trp_no_auto_translate_selectors', static function ( array $selectors, string $language ): array {
    $selectors[] = '.myplugin-brand-copy';
    return $selectors;
}, 10, 2 );

Do not use broad selectors like .content, main, or .product; they hide too much from translation.

Forms, nonces, and volatile values

Mark volatile technical values as not translatable:

Good pattern:

printf(
    '<input type="hidden" name="_wpnonce" value="%s" data-no-translation />',
    esc_attr( wp_create_nonce( 'myplugin_action' ) )
);

Do not put translatable prose inside value attributes when a visible <label> or help text can carry it.

AJAX and REST

For front-end requests:

For public endpoints, keep permission checks independent of language. TranslatePress language cookies and URL slugs are presentation state, not authorization.

Automatic Language Detection interaction

Business includes the Automatic User Language Detection add-on. It localizes trp_language_cookie_data, sets a trp_language cookie, can append popup/hello-bar UI in wp_footer, and may use trp_lang_switch during language switch actions.

When testing theme/plugin output:

Critical rules

Cross-references

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.