• Resolved matteogreco

    (@matteogreco)


    Hi! I’m trying to write a small plugin to make FacetWP’s facets translatable using TranslatePress. I’ve been instructed by their support team to do (at the minimum) this:

    
    add_action( 'wp_footer', function() {
        $lang = some_translate_function_to_get_current_language(); // <---
        HTTP || {}; FWP_HTTP.lang = '$lang';</script>";
    }, 30 );
     
    // maybe needed depending on how translate press works
    add_filter( 'facetwp_query_args', function facetwp_query_args( $args ) {
        $http = FWP()->facet->http_params;
        if ( isset( $http['lang'] ) && $http['lang'] !== $this->default_language ) {
    	// whatever translatepress needs to switch to current language in query
        }
        return $args;
    } );
    

    So, I need to figure out:

    1. How do I programmatically get the default language? Through a new TRP_SETTINGS object and then $settings[‘default-language’]?
    2. How do I programmatically get the current language? global $TRP_LANGUAGE?
    3. How do I programmatically have TranslatePress switch to the current language, like WPML does with do_action( ‘wpml_switch_language’, $language_code )? Do I even need to?

    Cheers,

Viewing 1 replies (of 1 total)
  • Dragos

    (@dragosvrejiu)

    Hello,

    Sorry for the late reply!

    >How do I programmatically get the default language? Through a new TRP_SETTINGS object and then $settings[‘default-language’]?

    $trp = TRP_Translate_Press::get_trp_instance();
    $trp_settings = $trp->get_component( ‘settings’ );
    $settings = $trp_settings->get_settings(); $default_language = $settings[“default-language”];

    >How do I programmatically get the current language? global $TRP_LANGUAGE?

    Yes.

    >How do I programmatically have TranslatePress switch to the current language, like WPML does with do_action( ‘wpml_switch_language’, $language_code )?

    It is enough to change the variable $TRP_LANGUAGE.
    Something like: $TRP_LANGUAGE = $new_language_code;

    >Do I even need to?

    I don’t know how FacetWP works , but TP doesn’t create duplicate posts;So,all the queries after meta information work.

    You might not need to change the language in order to do the filter query.

    Let me know how this goes and good luck with your project!

    Best regards,

Viewing 1 replies (of 1 total)
  • The topic ‘FacetWP integration’ is closed to new replies.