Background of the issue:
Whenever I do an ajax call from the frontend of my website, WPML seems to serve me whatever language is configured in the backend (admin screen) of the website. I am on the English site browsing it from the client (frontend) side of things but logged in as an administrator and have my admin language setup as French. Whenever I do any ajax calls on the front end of the site using wp.apiRequest call or The Events Calendar ajax calls, I am served the admin language (French) content. Link to a page where the issue can be seen: hidden link
Symptoms:
Ajax calls on the frontend are returning content in the backend (admin) language instead of the frontend language.
Questions:
Why are ajax calls on the frontend returning content in the backend language?
How can I ensure ajax calls return content in the frontend language?
What is the ajax call you are calling and what are the expected results ?
When logged in there is a cookie saved based on the admin language, if you give me more information regarding the action and desired results I'll be able to better help you.
I am noticing this issue with several ajax calls, one is a call to the WordPress POSTS Rest Controller for searching the posts on the site.
This ajax call is using the wp.apiRequest function so it is sending the proper nonce to verify if the user is logged in etc. I have since fixed this by simply just appending lang={language_code} to the query parameters to force WPML to use that specified language.
I was hoping that it would instead use the current front end language cookie instead though but that issue has been resolved.
The other issue that I am not able to resolve though is the ajax calls from "The Events Calendar" plugin, it works fine when you are not logged in or if you are logged in and the admin language matches the front end language.
However as soon as the admin language differs from the front end language there is an issue.