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 has 5 replies, 2 voices, and was last updated 3 years ago by
Ernest Marcinko.
-
AuthorPosts
-
June 29, 2023 at 1:18 pm #44504
Triner
ParticipantHi 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.jsI 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
JonasJune 29, 2023 at 2:33 pm #44508Ernest Marcinko
KeymasterHi,
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.
June 29, 2023 at 2:46 pm #44509Triner
ParticipantThanks 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?
June 29, 2023 at 2:49 pm #44510Ernest Marcinko
KeymasterThen I remembered correctly.
That should actually resolve the problem, the action you need to add to the list is:
ajaxsearchpro_searchJune 29, 2023 at 3:33 pm #44511Triner
ParticipantYep, 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.
June 30, 2023 at 12:31 pm #44516Ernest Marcinko
KeymasterYou are very welcome! Let me know if you find any solution!
-
AuthorPosts
- You must be logged in to reply to this topic.