Hi,
After lots of exploration, I found a solution of multi language from the discussion but stuck on the mobile part by using the lightboxes.
The issue is only the text on mobile menu will switch the language but not the content on the page. So when I close the menu, the content on the page won’t change. Can anyone kindly help?
Here is the desktop version.
https://hellogpeng.wixsite.com/test2
Here is the mobile screenshot.
//The code is applied on Home and About page
import wixWindow from ‘wix-window’;
import { local } from ‘wix-storage’;
import wixData from ‘wix-data’;
$w.onReady( function () {
//detect mobile and show the menu button.
if (wixWindow.formFactor === “Mobile” &&
wixWindow.rendering.renderCycle === 1) {
$w(“#mmenuButton”).show();
}
let locale = wixWindow.locale;
let lang = local.getItem(‘siteLangPref’);
if (!lang) {
//using the locale in case the user hasn’t chosen the relevant
// language
if (locale === “zh-tw”) {
lang = ‘chinese’;
} else {
lang = ‘english’;
}
}
traslateAll(lang);
});
function traslateAll(lang) {
wixData.query(‘Translation’).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 ENButton_click(event) {
const lang = ‘english’;
local.setItem(“siteLangPref”, lang);
traslateAll(lang);
}
export function ZHButton_click(event) {
const lang = ‘chinese’;
local.setItem(“siteLangPref”, lang);
traslateAll(lang);
}
export function mmenuButton_click(event, $w) {
wixWindow.openLightbox(‘mobilemenu’);
}
Database / Translation
// The code is applied to Lightboxes / mobilemenu page
import wixWindow from ‘wix-window’;
import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;
$w.onReady( function () {
let locale = wixWindow.locale;
let lang = local.getItem(‘siteLangPref’);
if (!lang) {
//using the locale in case the user hasn’t chosen the relevant
// language
if (locale === “zh-tw”){
lang = ‘chinese’;
}
else {
lang = ‘english’;
}
}
traslateAll(lang);
});
function traslateAll(lang) {
wixData.query(‘Translation’).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 ENButton_click(event) {
const lang = ‘english’;
local.setItem(“siteLangPref”, lang);
traslateAll(lang);
}
export function ZHButton_click(event) {
const lang = ‘chinese’;
local.setItem(“siteLangPref”, lang);
traslateAll(lang);
}
Thanks in advance.
Grace