Multi language problem

Trying to make multi language button that changes all the text to selected language once clicked I found a code in wix but I have trouble integrating it.
I just need one example how to integrate it.

The thread does not show how to connect each items to DB.

Can anyone help me?

import {local} from 'wix-storage';
import wixData from 'wix-data';

$w.onReady(function () {
	let lang = local.getItem('siteLangPref');
	if (!lang) {
		lang = 'english';
	}
	traslateAll(lang);
});

function traslateAll(lang) {
	wixData.query('NewCollectionName').find().then(result => {
		const allItems = result.items;
		allItems.forEach(item => {
			const selector = item.componentId;
			if ($w(`#${selector}`).type === '$w.Button') {
				$w(`#${selector}`).label = item[lang];
			} 
			if ($w(`#${selector}`).type === '$w.Text') {
				$w(`#${selector}`).text = item[lang];
			}
		});
	});
}

export function chineseButton_click(event) {
	const lang = 'chinese';
	local.setItem("siteLangPref", lang);
	traslateAll(lang);
}

export function englishButton_click(event) {
	const lang = 'english';
	local.setItem("siteLangPref", lang);
	traslateAll(lang);
}

Hi,
You should add the component ID as a column to your DB:

const selector = item.componentId; 

The name of the column in this case is componentId.

I hope it’s clearer.
Tal.

Thank you so much finally got it! WIX SHOULD PAY YOU TO DO THIS KIND OF WORK

Well… they do :wink:

Hi All, i’ve got a similar trouble, so i’ve opened another topic as it’s a bit different the issue, maybe someone will help me or some one has that same proiblem as mine…

This is it https://www.wix.com/corvid/forum/community-discussion/wixdata-switch-language%3Fpage%3D1%26dl%3D5cd58e5a60d990001609e19f