Hi all. I’ve started my solution for a multilingual database. I saw ‘plugins’ for multilingual WIX sites, but that was with translations of files. I personally don’t like the approach, but understand the ease of it. This post is on my solution for a flexible multilingual site with database driven content. When I’m further, I’ll update the ‘todos’. I’m just starting my WIX site, but also try to implement these major parts from point one. Feel free to comment.
Todos:
- check if session usage is working in the first place
- add ‘default’ to the page code in case session is not possible
Database Setup:
- language table consisting of ‘language_code’, ‘flag’, ‘description’. Here you can add any other language
- A data table with the ‘non translated’ table. These are columns like ‘active’, ‘record_id’, ‘reference_to_some_table’, ‘some_number_values’
- A data translation table with the ‘translated’ columns. These are columns like ‘description’, ‘details’. Anything which is different in a different language. Important, this table must contain a link to the ‘language_code’. In my case the primary key of this table is the ‘language_code’ suffixed with the ‘record_id’
Extra code on ‘site’
I’m storing site settings in a table, and one is the default language. I want to put that in a session parameter on site load. Also, I clear the session when it is loaded. So in the ‘site’ code I put this.
— Site Code —
import {session} from ‘wix-storage’;
…
$w.onReady(function () {
// Get Site Settings and adjust site accordingly
wixData.query(“site_settings”)
.eq(“setting_code”, “venture_the_trails”)
.find()
.then((oSiteSettings) => {
…
// Set session information
session.clear();
if (oSiteSettings.items[0].setting_language && oSiteSettings.items[0].setting_language.length === 2) {
session.setItem(“vttLanguage”, oSiteSettings.items[0].setting_language);
} else {
session.setItem(“vttLanguage”, “en”);
}
…
});
});
— Site Code —
As you can see, I also added a default check to see my parameter is actually filled and has two characters, else it defaults to ‘en’.
Then on a page with a dataset, I add ‘page’ code to add extra filters. I’m still tweaking this part, but my starting point is functional.
— Page Code —
import wixData from ‘wix-data’;
import {session} from ‘wix-storage’;
$w.onReady(function () {
// Add language filter to dataset
$w(“#dataset1”).setFilter( wixData.filter()
.startsWith(“translation_id”, session.getItem(“vttLanguage”))
);
});
— Page Code —
So here I get the dataset (just an example in this case) and set the filter for it. Currently I do a ‘startsWith’ on the ‘translation_id’ column. The values here are e.g. ‘en_rec1’, ‘en_rec2’, ‘nl_rec1’. I want to switch this to my ‘language_code’ column with ‘eq’ but that doesn’t work yet. I just read out the session info.