• Resolved Lukasz

    (@wpfed)


    Hi,

    This code below is taking precedence over my custom functions, so get_locale() and translation functions __() are no longer working. I’m using Polylang free version, and I basically create a form for each language and then add it to the page. So for example when I am on a French page, I add the French contact form shortcode.

    Here’s the most recent CF7 code causing the issue:

    $output = wpcf7_switch_locale(
    		$contact_form->locale(),
    		$callback,
    		$contact_form, $atts
    	);
    

    Here’s what fixes the issue:

    $output = wpcf7_switch_locale(
    		get_locale(),
    		$callback,
    		$contact_form, $atts
    	);
    

    I’m doing some workarounds like so but I still have issues with _() translation functions. And I’m not only using it in wpcf7_form_hidden_fields hook, also in wpcf7_init to create custom tags, wpcf7_add_form_tag.

    $current_locale = get_locale();
    add_filter( 'wpcf7_form_hidden_fields', function( $hidden_fields ) use ( $current_locale ) {
        return filter_wpcf7_form_hidden_fields( $hidden_fields, $current_locale );
    }, 10, 1 );
    

    Is this the proper way to pull the language from the form and not instead from the actual page so it matches the page language? If is the way, can I somehow hook into to change the locale? Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Where can we see the website in question?

    Thread Starter Lukasz

    (@wpfed)

    @takayukister found the issue!, looks like CF7 stores the locale in post_meta and it had the incorrect locale, maybe since I updated from a very old version of Cf7 or it was just never set correctly.
    Here’s what I found in the DB:

    INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (89765,'_locale','en_CA');
    //Fix CF7 locale, set manually to desired locale, remove this line once set.
    update_post_meta( 89765, '_locale', 'fr_CA' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.