Translate selected JSON payload fields

pom_translate_translate_json_payload( $data, string $locale, string $context = '', ?string $current_key = null, ?array $allowlist = null, ?bool $allow_translation = null ) recursively processes arrays and objects.

Pass an explicit allowlist for integration-owned payloads:

$data = pom_translate_translate_json_payload(
    $data,
    'es_ES',
    'rest',
    null,
    array( 'title', 'message' )
);

Base-locale requests return the original data. Non-string values and protected placeholder tokens remain unchanged. HTML strings use the HTML fragment translator; plain REST/AJAX strings use already registered translations without creating unknown entries.

An empty allowlist permits all branches, so public integrations should normally supply exact textual keys or extend the corresponding field-allowlist filter. Never translate IDs, URLs, amounts, booleans, tokens, or schema keys.

Translation mutates object properties in the returned object. Validate the final response schema and escape at the serialization or rendering boundary.