Hooks

This document provides instructions on how to extend ConveyThis's translation capabilities for WordPress by customizing its translation rules and targeting specific code elements.



Extending Translation to Custom HTML Attributes

ConveyThis uses built-in rules to identify translatable content. You can use the conveythis_get_dom_checkers filter to extend this functionality and instruct the plugin to translate content within specific HTML attributes that you define.

Use Case:

Imagine you have data stored in a custom data-slide-title attribute and want to ensure it gets translated.

Code Example:

add_filter( 'conveythis_get_dom_checkers', 'custom_conveythis_dom_check' );
function custom_conveythis_dom_check( $dom_checkers ) {
  if (!class_exists('CustomAttributeChecker')) {
    class CustomAttributeChecker  {
      const DOM       = '[data-slide-title]'; 
      const PROPERTY  = 'data-slide-title';
      const WORD_TYPE = TEXT; 
    }
    $dom_checkers[] = '\CustomAttributeChecker'; 
  }
  return $dom_checkers;
}


Translating Custom Keys in JSON Data

ConveyThis translates certain values within JSON responses by default and HTML content. However, you can use the conveythis_add_json_keys filter to target additional keys for translation.

Use Case:

Imagine you have a custom key named "message" in your JSON that contains text you want to translate. By default, ConveyThis might overlook this key.

Code Example:

add_filter( 'conveythis_add_json_keys', 'custom_conveythis_add_json_keys' );

function custom_conveythis_add_json_keys( $keys ) {
  $keys[] = 'message'; // Add your custom key here
  return $keys;
}

This page was last edited on 2024-12-23 19:46

Powered by Wiki|Docs

This page was last edited on 2024-12-23 19:46

Conveythis.com
Copyright © All rights reserved

Powered by Wiki|Docs