• Resolved jpvanmuijen

    (@jpvanmuijen)


    Hi,

    This plugin is still working great, awesome job.

    I do have one issue though. I have a multi-language site using the WPML plugin. Default language is Dutch, and I have (amongst others) English translations of several post types. However, in the autocomplete, it always shows the default Dutch post type label.

    Any ideas how to push the post type label for different languages to my index? Without having to edit each one individually of course. Seems like it uses the Label entered on the Autocomplete settings page when re-indexing.

    Any help would be appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not guaranteed to be a perfect solution, but we know that this code snippet exists that could help out with what you’re trying to do.

    https://github.com/algolia/algoliasearch-wordpress/issues/802#issuecomment-473908993

    Thread Starter jpvanmuijen

    (@jpvanmuijen)

    Thanks, kinda glad to see I’m not the only one having this issue.
    However, that code snippet throws a critical error when I update an item.
    I will investigate to see if I can find out what’s causing this, but in the meantime there may be other suggestions?

    Thanks again

    Thread Starter jpvanmuijen

    (@jpvanmuijen)

    A workaround would be to hide the post type labels from the autocomplete window in other languages, but I can’t seem to find where to remove or hide that (I assume in autocomplete.php).
    Any suggestions?

    • This reply was modified 4 years, 10 months ago by jpvanmuijen.
    Plugin Contributor Richard Aber

    (@richaber)

    Howdy @jpvanmuijen,

    I imagine the error you received is because the shared_attributes function in the linked example did not return the $attributes array.

    First, make sure you have you read and followed the instructions for WPML integration found at https://community.algolia.com/wordpress/wpml.html

    Following those instructions will ensure that the content itself has a wpml.locale attribute in the index for faceting, and will expose a window.current_locale JS variable in the page, which you can use for further customization.

    From there you should be able to customize the Algolia JS widgets in the autocomplete.php and instantsearch.php templates for your use case. There is additional documentation about customizing those templates here https://community.algolia.com/wordpress/customize-autocomplete.html and here https://community.algolia.com/wordpress/customize-search-page.html.

    I believe the data.label and config[‘label’] in autocomplete.php is what you would want to look further into… You might be able to use the data.label in conjunction with a custom JS var to swap the text to another language.

    I have created some example code in this gist to do such a thing, and tested it locally. Note that my default language is English, and I used Spanish (very badly translated by Google) in my example code. So you will need to adjust for your language.

    Give that a shot and let us know if it helps solve your issue.

    Thread Starter jpvanmuijen

    (@jpvanmuijen)

    This is excellent, thank you very much for your extensive reply!

    I’ve hidden the labels for other languages for now. I’m a bit embarrassed I didn’t find data.label by myself..
    The JS label translation makes sense as well, since I only have a few languages and post types. I’ll give that a shot in the coming days.

    Is there a way to make a donation by the way? I’m quite dependant on your plugin for one of my clients, so would be happy to pay for it.

    Thanks again!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WPML => post_type_label for different languages’ is closed to new replies.