Search not working on pages translated by Weglot

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Search not working on pages translated by Weglot

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 11 months, 3 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #44504
    Triner
    Triner
    Participant

    Hi Ernest

    I’d like to use Ajax Search Pro for the global site search and Weglot to translate the website. Now I have the problem that on the translated page the search does not work anymore. When I enter a search term, no results are loaded and the following error message is displayed in the browser console:
    Uncaught SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 371 of the JSON data
    The message is output from the following file: /wp-content/plugins/ajax-search-pro/js/min/plugin/optimized/asp-core.js

    I saw that you didn’t have the capacity to take care of compatibility with Weglot until now. Maybe something has happened in the meantime? If not, could you give me a jump start to look for a solution myself?

    Kind regards
    Jonas

    #44508
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    The error is issued because the search response data is modifed – I assume weglot tries to translate everything “on the fly” and also hooks into the request response. However the response data contains JSON structured information, which should not be changed, otherwise it is broken and can’t be decoded. JSON is normally used with ajax requests, so I am not exactly sure why would the translator try to change the XHR response data. I guess if the XHR response format is not exclicitly JSON then it will just automatically apply.

    I believe we tried to solve this some time ago, and if I recall correctly, then the main bascially unsolvable issue with this plugin was, that it translated in real time during output. I belive the translations weren’t stored as separate post type objects, but additional data somewhere external, which was not searchable.

    I recall someone had a similar issue, but then he never responded. The only possible solution to this is to either add exceptions – if possible in a form of regular expressions, so that some string contents including the JSON data are left as is without translation. I don’t know if weglot has a feature like that, I am not familiar with it.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #44509
    Triner
    Triner
    Participant

    Thanks for your feedback, Ernest.

    It is true that Weglot translates “on the fly” and the translations are not stored locally but on Weglot’s servers.

    Actually, I have not enabled the translation of the search queries. Could possibly the approach described here, excluding Ajax actions for translation, help? If so, do you have any idea what I would need to specify as the value of the $ajax_action[] array?

    #44510
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Then I remembered correctly.

    That should actually resolve the problem, the action you need to add to the list is: ajaxsearchpro_search

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #44511
    Triner
    Triner
    Participant

    Yep, that snippet in place prevents the error message and the search can display the results again. However, they are now displayed in the original language.

    I looked at the XHR response via the browser console. As you said, Weglot translates them and in doing so, it seems to misplace an apostrophe in my case. A corrective translation rule in Weglot seems to me to be the most promising solution too, however I cannot find this XHR response in the translation table in my Weglot dashboard. I will contact Weglot support with this information.

    Thank you very much for your support.

    #44516
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You are very welcome! Let me know if you find any solution!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.