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:
NAME
TYPE
DESCRIPTION
The language's full name.
The language's locale code, which represents a set of language-related formatting preferences.
The language's two-letter code.
The language's three-letter country code.
Whether the language is the site's primary language.
Was this helpful?
1import wixWindowFrontend from 'wix-window-frontend';23// ...45let languages = wixWindowFrontend.multilingual.siteLanguages;67/* languages is:8 * [9 * {10 * "name": "English",11 * "locale": "en-us",12 * "languageCode": "en",13 * "countryCode": "USA",14 * "isPrimaryLanguage": true15 * }, {16 * "name": "Spanish",17 * "locale": "es-es",18 * "languageCode": "es",19 * "countryCode": "ESP",20 * "isPrimaryLanguage": false21 * }, {22 * "name": "Chinese",23 * "locale": "zh-cn",24 * "languageCode": "zh",25 * "countryCode": "CHN",26 * "isPrimaryLanguage": false27 * }28 * ]29 */
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.
1import wixWindowFrontend from 'wix-window-frontend';23// ...45$w.onReady(function () {6 const languages = wixWindowFrontend.multilingual.siteLanguages;78 let languageOptions = languages.map((obj) => {9 return { label: obj.name, value: obj.languageCode };10 });1112 const currentLanguage = wixWindowFrontend.multilingual.currentLanguage;13 const filteredLanguageOptions = languageOptions.filter(obj => obj.value !== currentLanguage);1415 $w('#languageDropdown').options = filteredLanguageOptions;1617 $w("#languageDropdown").onChange((event) => {18 wixWindowFrontend.multilingual.currentLanguage = event.target.value;19 });20});21