Search.../

siteLanguages

Gets information about the site's languages.

Description

The siteLanguages property returns an array of SiteLanguage objects containing information about all the languages that the site is set to display in.

Type:

Array<SiteLanguage>Read Only
NAME
TYPE
DESCRIPTION
name
string

The language's full name.

locale
string

The language's locale code, which represents a set of language-related formatting preferences.

languageCode
string

The language's two-letter code.

countryCode
string

The language's three-letter country code.

isPrimaryLanguage
boolean

Whether the language is the site's primary language.

Was this helpful?

Get information about the site's languages

Copy Code
1import wixWindowFrontend from 'wix-window-frontend';
2
3// ...
4
5let languages = wixWindowFrontend.multilingual.siteLanguages;
6
7/* languages is:
8 * [
9 * {
10 * "name": "English",
11 * "locale": "en-us",
12 * "languageCode": "en",
13 * "countryCode": "USA",
14 * "isPrimaryLanguage": true
15 * }, {
16 * "name": "Spanish",
17 * "locale": "es-es",
18 * "languageCode": "es",
19 * "countryCode": "ESP",
20 * "isPrimaryLanguage": false
21 * }, {
22 * "name": "Chinese",
23 * "locale": "zh-cn",
24 * "languageCode": "zh",
25 * "countryCode": "CHN",
26 * "isPrimaryLanguage": false
27 * }
28 * ]
29 */
Create a dropdown used to change between available languages

This example assumes you have a site set up to display in multiple languages. It also assumes you have a dropdown element with the ID languageDropdown.

When the page loads, the site's available languages are retrieved. Then, the JavaScript map() function is used to change the retrieved language information into the format expected by the dropdown's options property. Next, the JavaScript filter() function is used remove the current language from the list. Finally, the dropdown's options property is set using the formatted language list.

An onChange event handler is registered for the dropdown element. The event handler changes the site's current language based on the language chosen by the user.

Copy Code
1import wixWindowFrontend from 'wix-window-frontend';
2
3// ...
4
5$w.onReady(function () {
6 const languages = wixWindowFrontend.multilingual.siteLanguages;
7
8 let languageOptions = languages.map((obj) => {
9 return { label: obj.name, value: obj.languageCode };
10 });
11
12 const currentLanguage = wixWindowFrontend.multilingual.currentLanguage;
13 const filteredLanguageOptions = languageOptions.filter(obj => obj.value !== currentLanguage);
14
15 $w('#languageDropdown').options = filteredLanguageOptions;
16
17 $w("#languageDropdown").onChange((event) => {
18 wixWindowFrontend.multilingual.currentLanguage = event.target.value;
19 });
20});
21