Purpose

Translate or modify the content of a specific DataTable column programmatically. This action allows developers to dynamically localize or adjust column data before it is rendered.

Usage

add_action( 'wr_form_add_scripts', array( $this, 'translate_datatable_column_project_status' ), 10, 3 );

Parameters

  • $text (string): The current content of the DataTable column, typically in JSON format.
  • $text_domain (string): The text domain used for localization.
  • $dt_settings (array): The settings associated with the DataTable, including its identifier.

Use Case

This functionality is useful when:

  • You need to translate or modify specific column data in a DataTable dynamically.
  • Customizing or localizing the titles or other properties of column entries is required based on context or user settings.

Implementation Example

The following example translates the titles of entries in a DataTable column for a specific DataTable identified by datatable_identifier

add_action( 'wr_form_add_scripts', array( $this, 'translate_datatable_column_project_status' ), 10, 3 );
 
public function translate_datatable_column_project_status( $text, $text_domain, $dt_settings ) {  
    if ( (int)$dt_settings['id'] !== 'datatable_identifier' ) {  
       return $text;  
    }  
  
    $text = json_decode( $text, ARRAY_A );  
    if ( is_array( $text ) ) {  
       foreach ( $text as &$entry ) {  
          $entry['title'] = __( $entry['title'], $text_domain );  
       }  
       $text = json_encode( $text );  
    }  
  
    return $text;  
}