Translating a WIX site using code. Possible??

Hi all.

I have a Portuguese site, and as most of you guys know, WIX does not offer a simple tool to translate a site. I was wondering if using the code function, it would be possible to translate a site using any sort of way, even Google Translate, which does not work inside the html frame on a WIX site.

Does anyone knows anything about it? I really need some help. I was already decided to move to other website platform only due to this translation issues, but I just saw this Code option.

I appreciate any thoughts.

Thanks,

Hi!
Main idea that i have regarding this - store every label that you need to translate in collection.
I mean collection with 2 items and X columns - 1 column for every possible label/text that needs to be translated.
Then you can connect all labels on site to this collection via dataset and change translations via next/previous actions on dataset.

Please notice that so far it’s not possible to translate any verticals except editor - i mean if you have wixStores or Bookings, there is no way to change their labels.
But team is working on this now

Mikhail Spirin, thanks mate. I will try that, but I hope Wix release this tool as soon as possible.
There’s a lot of complaints about this. Anyway… thanks again.

Hay Axe,

Here is a quick solution for static pages, not for dynamic pages. For dynamic pages you will need to modify this solution a bit. The main difference is that on dynamic pages you need to handle differently texts that are connected to a dataset vs non connected texts.

I have created a site with three text elements and two buttons -


Then I have created a collection with the following fields -


I did not write all the content in this collection - I have let the site actually generate most of the collection content - and I had only to write the FR version.

Lets look at the code.

The code has two parts - inserting into the collection all the data for the EN version, reading it from the site design, and making translations.

The first part -

import wixData from "wix-data";
import wixLocation from "wix-location";

let pageId; 

$w.onReady(() => {
    pageId = wixLocation.path.join('/') || 'home';
    prepereTranslations();
})

function prepereTranslations() {
    $w('Text').forEach( async (txt) => {
        let item = await wixData.get('translations', pageId + '.' + txt.id);
        if (!item)
            wixData.insert('translations', {
                _id: pageId + '.' + txt.id,
                elementId: '#' + txt.id,
                pageId: pageId,
                en: txt.text
            });
    })
}

The $w(‘Text’) selector lets me get all the Text elements on the page. With that, I check that each has an entry in the translations database and create one if it does not exist. I have added the elementId, pageId and _id to the saved item to make sure I can fetch the translations per page and per element.

The second part -

async function loadTranslations(lang) {
    let res = await wixData.query('translations')
        .eq('pageId', pageId)
        .find();
    res.items.forEach(item => {
        $w(item.elementId).text = item[lang];
    });	
}

export function en_click(event, $w) {
    loadTranslations('en');
}

export function fr_click(event, $w) {
    loadTranslations('fr');
}

Clicking on the buttons, I read the translations for a page, fetch the element and set it’s text to the text read from the database.

Yoav/Axe, I tried this code, got error that forEach is undefined from part 1 above – $w(‘Text’).forEach ( async (txt) => {

Dear Wix - I’m screwed. I don’t understand any of what I read above. All I know is that I convinced my client to let me design their site using WIX… they are required by the state to have a translate button…I embeded the google translate button and assumed it would work when I went live…low and behold I find out even though I am able to embed it - it does not work with WIX… it never occurred to me that it would not work. I just read soooooo many comments from people saying the same thing - why can’t you make it work with WIX? I don’t know what to do - other than rebuild a spanish version of the entire site on my own dime - but I certainly can’t do that for every language. Does anyone else have any insight for someone who all the code talk above does not make any sense at all?

Year 2024. Are they still working on this issue?

1 Like

what happens at wix? are they any employees or devs here who work at wix?