Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

WPML translated facets #802

Open
dseidl opened this issue Oct 23, 2018 · 3 comments
Open

WPML translated facets #802

dseidl opened this issue Oct 23, 2018 · 3 comments

Comments

@dseidl
Copy link

dseidl commented Oct 23, 2018

What did you expect to happen?

translated text for the post_type_label facet.

What happened instead?

It always shows the main language text

How can we reproduce this behavior?

setup a simple index with wpml enabled and followed the wpml instructions here: https://community.algolia.com/wordpress/wpml.html

Technical info

  • WordPress version: 4.9.8
  • Algolia Search plugin version: 2.11.2
@damircalusic
Copy link

damircalusic commented Mar 8, 2019

I have the same Issue. The post_type_label is not being translated.

Technical
WordPress 5.1
Algolia 2.11.3
WPML 4.2.4.1

@sondreal
Copy link

Also got this mind numbing issue:
Wordpress : 5.1
WPML: 4.2.0
Algolia 2.11.3

@damircalusic
Copy link

damircalusic commented Mar 18, 2019

I have fixed a temporary solution fix that works great.

function shared_attributes(array $attributes, WP_Post $post){
	$lang = '';

	// WPML is active, set correct language
	if(function_exists('icl_object_id')){
		global $sitepress;
		$lang = $sitepress->get_current_language();
	}

	$attributes['wpml'] = apply_filters('wpml_post_language_details', null, $post->ID);
	
	// If post post type index the following
	if('post' == $post->post_type){
		$attributes['post_type_label'] = ($lang == 'en') ? 'Articles' : 'Artikler';
	}
	
	// If service post type index the following
	if('service' == $post->post_type){
		$attributes['post_type_label'] = ($lang == 'en') ? 'Services' : 'Tjenester';
	}
}

function posts_index_settings(array $settings){
 $settings['attributesForFaceting'][] = 'wpml.locale';
  
 return $settings; 
}

add_filter('algolia_searchable_post_shared_attributes', 'shared_attributes', 10, 2); // sharing attributes
add_filter('algolia_searchable_posts_index_settings', 'posts_index_settings'); // indexing settings

As you can see we change the post_type_label attribute and when indexing the results the languages are separated from eachother in Algolia. The English version is indexed within the english labels and the other language is indexed on its language.

This works perfectly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants