• Hello! Translatepress,

    Thanks for your amazing creation. My colleagues love it.
    At the moment, we are creating a plugin that could update Translatepress translation of custom fields in product inventory. This part works great by using functions in class-query.php

    On the other part, after customer edit same translated text in Translatepress editor, it saves the text through ajax API in class-editor-api-regular-strings.php with action method save_translations.

    We would like to add support so that by the time the save translations is called, additional action could be done such as updating back to the custom fields in our case so that the 2-ways update(both direction) will be completed. As a result, the customer does not need to update the custom fields by jumping back to the product inventory. They could manage it in both place.

    So we would like to propose the following changes for you to review.
    The following is an example for regular text saving logic.
    It might be good to add to gettext also for future use cases, there are lots of possibilities.

    
     /*
      * Save translations from ajax post.
      *
      * Hooked to wp_ajax_trp_save_translations_regular.
      */
      public function save_translations(){
      if ( defined( 'DOING_AJAX' ) && DOING_AJAX && current_user_can( apply_filters( 'trp_translating_capability',  'manage_options' ) ) ) {
          check_ajax_referer( 'save_translations', 'security' );
          if ( isset( $_POST['action'] ) && $_POST['action'] === 'trp_save_translations_regular' && !empty( $_POST['strings'] ) )  {
              $strings = json_decode(stripslashes($_POST['strings']));
              $this->save_translations_of_strings( $strings );
          }
      }  
              
      do_actions( 'save_translations_extra_actions' );
    
      echo trp_safe_json_encode( array() );
      die();
    }

    `

    do_actions( 'save_translations_extra_actions' ); will be very handy because it allows additional operation while allow custom checking and logic.

    Or if translatepress already have other way(s) to accomplish the same thing, it would be grateful if you could share and point the direction.

    Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Anghel Emanuel

    (@anghelemanuel99)

    Hello there,

    Thank you for your interest in our plugin!

    Yes, that will be great. I made a request for this and we want to implement this in the next update.

    Have a great day!

    Kind Regards,

    Plugin Author Razvan Mocanu

    (@razvanmo-1)

    Hi,

    I added an action at the time of manually changing translation of user-driven content text (not plugins/theme text) in the Translation Editor. The two parameters are the array of strings that are being updated and the TP settings.

    do_action('trp_save_editor_translations_regular_strings', $update_strings, $this->settings);

    I hope this will be useful for your use case.

    Best regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add an action hook in Save translations for editor api’ is closed to new replies.