Multilingual fetching in ReactJS

220 Views Asked by At

I need to fix a big issue about multilingual support in a decoupled Drupal React block. Basic UI translations are based on i18next, and it works. Where it goes wrong is with the additional data that I’m fetching separately from the Drupal Rest API for mapping.

In my carousel component , I’m using something as:

const [showPosts, setShowPosts] = useState()
    const apiUrl = '/rest/slider-custom.json'

    let displayData
    async function pullJson() {

        const response = await fetch(apiUrl)
        const responseData = await response.json()
        displayData = responseData.map(function(tour) {

The problem is that const apiUrl = '/rest/slider-custom.json' is loading exclusively the default English translation and I looking for a way to add a language variable in front of the /rest/slider-custom.json path.

Thought that would be simple, but can't solve that with my novice state in React. Any hint most welcome!

0

There are 0 best solutions below