How to select datasets with $w in wix studio in order to filter content based on language

Question:
How to select datasets with $w in wix studio in order to filter content based on language

Product:
Wix Studio

What are you trying to achieve:
I want to filter my Blog content based on the sites language. But the code i use is not working. It seems I am unable to connect the code to my dataset. Since its no longer part of the UI???

What have you already tried:
This is the Code i Use:

import wixWindow from 'wix-window';
import wixData from 'wix-data';

$w.onReady(function () {
    let language = wixWindow.multilingual.currentLanguage;
    if (language === "de") {
        $w("#NewsStorys").setFilter(wixData.filter().eq("language", "DE"));
    } else if (language === "en") {
        $w("#NewsStorys").setFilter(wixData.filter().eq("language", "EN"));
    }
});

export function repeater1_itemReady($item) {
    if (language === "de") {
        $w("#NewsStorys").setFilter(wixData.filter().eq("language", "DE"));
    } else if (language === "en") {
        $w("#NewsStorys").setFilter(wixData.filter().eq("language", "EN"));
    }
}

Additional information:
The ID is in any case “#NewsStorys” but the Error says:
An element with the ID “#NewsStory” does not exist on this page.

Im new to Velo and not experienced with code in general.
So is the Problem just the selection of the Dataset or something different?

Okay it seems to Work now, somehow i dont get it…
Now there is another problem with displaying the content.

On the german site the content is displayed properly.
But on the english site, the german Content is also displayed… how can i fix this?

import wixWindow from ‘wix-window’;
import wixData from ‘wix-data’;

// Declare the language variable outside so it is accessible in all functions below.
let language;

$w.onReady(function () {
// Now the variable is initialized inside the onReady function, but declared outside.
language = wixWindow.multilingual.currentLanguage;
setNewsStoriesFilter();
});

// This function sets the filter based on the current language.
function setNewsStoriesFilter() {
if (language === “de”) {
$w(“#NewsStorys”).setFilter(wixData.filter().eq(“language”, “DE”));
} else if (language === “en”) {
$w(“#NewsStorys”).setFilter(wixData.filter().eq(“language”, “EN”));
}
}

// Example of what you might want to do in a repeater itemReady function
export function repeater1_itemReady($w, itemData, index) {
// Here you can manipulate the repeater item elements, like setting text or images based on itemData
// For example:
// $w(“#textElement”).text = itemData.title;
}

Maybe this can help you out?

This revised code ensures that the language variable is accessible where needed and clarifies the purpose of the repeater1_itemReady function. Remember to replace #textElement and itemData.title with the actual IDs and fields you are using in your repeater.