• Lost whole evening, and decided to do it with JS. Will just write it if it can help somene, or maybe someone wants to do it better.

    First will I explain what I did, and gave up it for more easier solution.

    – Cusom snippet for functions.php to hook before sending CF7 mail and send tags data to custom post type.
    – Made custom post type (like Flamingo). One of the reasons is to be able to use Admin Columns plugin to arrange Post list as I wish. Second is of course translation of tag names (fields).
    – Then snippet for functions.php for one Metabox inside my custom post type. Just removed any saving abilities and converted fields to simple table field values output. Some kind of “show” Metabox where you cannot enter any data.

    This ended in relatively many lines of code. Not that it is for itself big problem, but when you most of it need to make for several different CF7 forms. Then it gets very complex and not easy to remember what goes where and why. Multipy this with all new websites.

    So, here is solution I decided for:

    – Make new JS file and add this code inside:

    (function($) {
      var thePage = $("body");
    
      thePage.html(thePage.html()
      .replace(/text-3056/g, 'Name')
      .replace(/your-email/g, 'E-Mail')
      .replace(/text-3496/g, 'Betreff')
      .replace(/your-message/g, 'Nachricht')
      );
    
    })(jQuery)

    – Add this code to functions.php:

    function add_our_script() {
     $action = flamingo_current_action();
    	$post_id = ! empty( $_REQUEST['post'] ) ? $_REQUEST['post'] : '';
    
    	if ( 'edit' == $action && Flamingo_Inbound_Message::post_type == get_post_type( $post_id ) ) {
    wp_register_script( 'translations', plugins_url( 'custom-functions/translations.js' ), true );
    wp_enqueue_script( 'translations' );
    	}
    }
    add_action( 'admin_head', 'add_our_script' );

    – If using translations.js inside theme folder adapt code accordinly.
    I decided to do it right from beginning and limit JS file only to Flamingo edit screen. But there is no need for it as CF7 fields calls very specific way (text-3056). This word wont be mentioned anywhere else in backend. It makes CF7 editing panel slow too for some reason. So better to limit it.

    https://ww.wp.xz.cn/plugins/flamingo/

The topic ‘Translate field labels’ is closed to new replies.