Multilingual database and dynamic pages

Hello,
My site is multilingual.
I created a database but the correct data is not selected when choosing a different language.
I know this feature is not available yet (Last posts about it are from Jan, 2019…) but I think there might be a solution with coding. I tried using this code :
import wixData from ‘wix-data’ ;

import wixWindow from ‘wix-window’ ;

$w.onReady( function () {

//TODO: write your page related code here…

$w( “#dynamicDataset” ).onReady( () => {

console.log( “the dataset is ready” );

update_items();

});

$w( “#dynamicDataset” ).onCurrentIndexChanged( (index) => {

console.log( “the item changed” );

update_items();

});

});

function update_items () {

const current_item = $w( “#dynamicDataset” ).getCurrentItemIndex();

let language = wixWindow.multilingual.currentLanguage;

let description_text;

console.log(current_item);

wixData.query( “PRODUITS” ).find().

then( (results) => {

if (language === “es” ){

description_text = results.items[current_item].description_es;

} else if (language === “fr” ) {

description_text = results.items[current_item].description_fr;

} else {

description_text = results.items[current_item].description_fr;

}

$w( “#text1” ).text = description_text;

});

}

But the description just disappears in both languages instead of selecting the correct description…

I am not familiar with this so any help would be great !
Thanks a lot !

Hello.

It seems the issue is due to the fact that getCurrentItemIndex( ) inside update_items () is running outside dataset’s onReady function. Therefore, the code runs while the dataset hasn’t loaded.

To resolve the issue, you should use call any code relating to current dataset item inside the dataset’s onReady function. You can refer to our API here: https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItemIndex

Good luck!

Thanks a lot for your reply Sam Eru !
Now I can have both languages but for a reason I ignore, the item shown is only the one from the last row of my dataset on all pages. What can I do to call each page description and not only this last one ?

Thank you very much.

import wixData from 'wix-data';

import wixWindow from 'wix-window';

$w.onReady(function () {

$w("#dynamicDataset").onReady( () => {

 console.log("the dataset is ready");

 update_items();

 let itemObj = $w("#dynamicDataset").getCurrentItem();

$w("#dynamicDataset").onCurrentIndexChanged( (index) => {

 console.log("the item changed");

 update_items();

});

});

function update_items () {

const current_item = $w("#dynamicDataset").getCurrentItemIndex();

let language = wixWindow.multilingual.currentLanguage; 

let description_text;

console.log(current_item);

wixData.query("PRODUITS").find().

then( (results) => {  

 if(language === "es"){

  description_text = results.items[current_item].description_es;

 } else if (language === "fr") {

  description_text = results.items[current_item].description_fr;

 } else {

  description_text = results.items[current_item].description_fr;

 }

 $w("#text1").text = description_text;

}); 

}
});