Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 18 replies, has 4 voices.

Last updated by miguelF-2 1 year, 8 months ago.

Assigned support staff: Sumit.

Author Posts
December 3, 2018 at 11:44 am #2961922

Martino

Hi there? Any update on this?

The FacetWP author helped my with a custom code that is working (while not that easy to update):


if (ICL_LANGUAGE_CODE == "en") {
add_filter( 'facetwp_facet_html', function( $output, $params ) {
    if ( 'target' == $params['facet']['name'] ) {
        $current_values = array( 'Addetti ai lavori', 'Appassionati' );
        $replace_values = array( 'Professionals', 'Coffee Fan' );
        $output = str_replace( $current_values, $replace_values, $output );
    }
    if ( 'tematiche' == $params['facet']['name'] ) {
        $current_values = array( 'Degustazione', 'Tecniche di produzione', 'Tecniche di preparazione' );
        $replace_values = array( 'Tasting', 'Production tecniques', 'Preparation tecniques' );
        $output = str_replace( $current_values, $replace_values, $output );
    }
    return $output;
}, 10, 2 );
 
function custom_translate( $input ) {
    $current_values = array( 'Addetti ai lavori', 'Appassionati', 'Degustazione', 'Tecniche di produzione', 'Tecniche di preparazione' );
    $replace_values = array( 'Professionals', 'Coffee Fan', 'Tasting', 'Production tecniques', 'Preparation tecniques' );
    return str_replace( $current_values, $replace_values, $input );
}
 
};

but with the most recent update of WPML it seems the
if (ICL_LANGUAGE_CODE == "en")
string isn't ok anymore.

Is it something I can solve? Or there is another workaround to this

Thanks,
m.

December 6, 2018 at 1:26 pm #2974077

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

As we discussed on another thread that "ICL_LANGUAGE_CODE" is still working without any issue. Please continue on another thread if you see any problem with the new version and this constant.

About this issue we updated the author on same time and suggested the workaround to keep filtres per language.

Thanks

April 8, 2019 at 8:11 am #3555341

miguelF-2

Hi,

I'm using Facet WP Conditional Logic. I can translate the labels of the select, but after JSON reload the select fields, the labels aren't translated.
I'm using this code

			if (ICL_LANGUAGE_CODE == "pt-pt") {
				add_filter( 'facetwp_facet_html', function( $output, $params ) {
				    if ( 'animais' == $params['facet']['name'] ) {
				        $current_values = array( 'na', 'no', 'yes' );
				        $replace_values = array( 'NA', 'Não', 'Sim' );
				        $output = str_replace( $current_values, $replace_values, $output );
				    }
				    return $output;
				}, 10, 2 );
				  
				function custom_translate( $input ) {
				    $current_values = array( 'na', 'no', 'yes');
				    $replace_values = array( 'NA', 'Não', 'Sim');
				    return str_replace( $current_values, $replace_values, $input );
				}
				  
			} else {
				add_filter( 'facetwp_facet_html', function( $output, $params ) {
				    if ( 'animais' == $params['facet']['name'] ) {
				        $current_values = array( 'na', 'no', 'yes' );
				        $replace_values = array( 'NA', 'No', 'Yes' );
				        $output = str_replace( $current_values, $replace_values, $output );
				    }
				    return $output;
				}, 10, 2 );
				  
				function custom_translate( $input ) {
				    $current_values = array( 'na', 'no', 'yes');
				    $replace_values = array( 'NA', 'No', 'Yes');
				    return str_replace( $current_values, $replace_values, $input );
				}
			};
April 8, 2019 at 10:11 am #3556439

miguelF-2

Solved

<?php
/*
Plugin Name: Custom Hooks
Plugin URI: <em><u>hidden link</u></em>
Description: A container for custom hooks
Version: 1.0
Author: FacetWP, LLC
*/

add_action( 'wp_head', function() {
?>
<script>
(function($) {
    //$('.facetwp-facet-animais').on('change', function() {
	    $(document).on('facetwp-loaded', function() {
	    	var getLangCode = '<?php echo apply_filters( 'wpml_current_language', NULL );  ?>';

	        if (getLangCode == 'pt-pt') {
	        	$('.facetwp-facet-animais select option:contains("na")').text('NA');
	  			$('.facetwp-facet-animais select option:contains("no")').text('Não');
	        	$('.facetwp-facet-animais select option[value="yes"]').text('Sim');
	        } else {
		        $('.facetwp-facet-animais select option:contains("na")').text('NA');
	  			$('.facetwp-facet-animais select option:contains("no")').text('No');
	        	$('.facetwp-facet-animais select option[value="yes"]').text('Yes');
	        }
		});
     //});
})(jQuery);
</script>
<?php
}, 100 );