Change query depending language

Dear All,

I have a website in English and Spanish. I would like to change the query depending the language chosen to feed the repeater’s button " ButtonSubCategoryArt ".

With my below code it is not working. Only the Spanish query (last) is set up.

What I made wrong?

Thank you for your help.
Best Regards,
Domivax

$w.onReady(function () {
if (wixWindow.multilingual.currentLanguage === "en") {
$w("#ButtonArt").label = "Art EN";
//QUERY TO GET DATA - ART
wixData.query("Sub-Category-002")
.eq("published", true)
.eq("category", "7a45da29-2181-41c5-97fd-72749202a982")
.limit(40)
.ascending("subCategoryEn")
.find()
.then(res => {
$w('#RepeaterSubCategoryArt').data = res.items;
});
$w('#RepeaterSubCategoryArt').onItemReady( ($w, items, index) => {
$w("#ButtonSubCategoryArt").label = items.subCategoryEn;
});
}
else if (wixWindow.multilingual.currentLanguage === "es") {
$w("#ButtonArt").label = "Art ES";
//QUERY TO GET DATA - ART
wixData.query("Sub-Category-002")
.eq("published", true)
.eq("category", "7a45da29-2181-41c5-97fd-72749202a982")
.limit(40)
.ascending("subCategoryEs")
.find()
.then(res => {
$w('#RepeaterSubCategoryArt').data = res.items;
});
$w('#RepeaterSubCategoryArt').onItemReady( ($w, items, index) => {
$w("#ButtonSubCategoryArt").label = items.subCategoryEs;
});
}
});

Have you read the Wix Multilingual API info and do you have the imports above your pages onReady function?
https://www.wix.com/corvid/reference/wix-window.multilingual.html#currentLanguage

Hi domivax,

maybe try to console.log your wixWindow.multilingual.currentLanguage value when you change the site’s language to english and then you can understand what went wrong.

did you enable wix multilanguage in your editor settings?

check out corvid api for changing current language :
https://www.wix.com/corvid/reference/wix-window.multilingual.html#currentLanguage

Gal.

Thanks GOS and Gal… and sorry for wasting your time. I found my mistake. It was a punctuation error });

Now it is working.

Thank you :slight_smile:

$w.onReady(function () {
if (wixWindow.multilingual.currentLanguage === "en") {
$w("#ButtonArt").label = "Art EN";
//QUERY TO GET DATA - ART
wixData.query("Sub-Category-002")
.eq("published", true)
.eq("category", "7a45da29-2181-41c5-97fd-72749202a982")
.limit(40)
.ascending("subCategoryEn")
.find()
.then(res => {
$w('#RepeaterSubCategoryArt').data = res.items;
}); // WRONG
$w('#RepeaterSubCategoryArt').onItemReady( ($w, items, index) => {
$w("#ButtonSubCategoryArt").label = items.subCategoryEn;
}); // CORRECT
});
}
else if (wixWindow.multilingual.currentLanguage === "es") {
$w("#ButtonArt").label = "Art ES";
//QUERY TO GET DATA - ART
wixData.query("Sub-Category-002")
.eq("published", true)
.eq("category", "7a45da29-2181-41c5-97fd-72749202a982")
.limit(40)
.ascending("subCategoryEs")
.find()
.then(res => {
$w('#RepeaterSubCategoryArt').data = res.items;
}); // WRONG
$w('#RepeaterSubCategoryArt').onItemReady( ($w, items, index) => {
$w("#ButtonSubCategoryArt").label = items.subCategoryEs;
}); // CORRECT
});
}
});