Getting the current language from editor(not frontend), but from component view or tsx(Polylang)

Hey, I’m wondering if somehow had to do this before. But I implemented a solution that works but I am wondering if there is a clean way to do it. So I have a component(.tsx) that list articles using the wordpress API, to fill out a Checkbox with articles titles, but because there are 2 languages for backend and frontend, when the user is writing a page or introducing the content, I need to filter the article list per current language, so I need to know in which language is editing the page.

So I did a reasearch a I tried a couple of things, but what it worked for me. Was… that I realized that … in the DOM from the page, polyland is always setting a language css class to the body, which actually have the current language from the editor, so I did a function to read this and I assigned the current language to the articles to display. However …in a future where for some reason they decided to change the name of the class, or something like, this might not work anymore. Do you have any idea? There is something maybe native, that can be better to use…

Is this question related to any of our tools?

Please read How to best ask questions on this forum and post some more information along with actual code if you’d like for this topic to be relisted

This topic was automatically closed after 42 days. New replies are no longer allowed.