Skip to main content

Language selector

v.3.0.1

Installation

yarn add @mercell/language-selector-react

Usage

Using the Language Selector component is as simple as importing it like this.

import { LanguageSelector, Country } from '@mercell/language-selector-react';

The Language Selector Component is intended to be used as a child of the GlobalMenu component.

Live Editor
Result

Types, definitions, etc.

LanguageSelectorProps
interface LanguageSelectorProps {
localeLng: string;
countries: Country[];
label: string;
id: string;
onClick: (locale: string) => void;
trackingAction?: TrackingActionType;
additionalTrackingParams?: Record<string, string | string[]>;
} & Omit<JSX.IntrinsicElements['nav'], 'onClick>'
NameTypeDefaultRequiredDescription
localeLngstring-yeslocale (e.g., en-GB)
countriesCountry[]-yesCountry is defined below
labelstring-yesaria-label
idstring-yesnecessary for aria-controls
onClickfunction-yesfunction for onClick
trackingActionTrackingActionType(_trackingEventType: string, _trackingProperties: Record<string, string | string[]>, defaultAction?: any ) => (e: any) => defaultAction(e),noMethod passed from context tracking hook to establish event tracking
additionalTrackingParamsRecord<string, string|string[]>{}noAny additional tracking properties which will be passed to all events
Link to TrackingActionType
Country
interface Country {
name: string;
language: string;
domain: string;
locale: string;
phonePrefix: string;
}
NameTypeDefaultRequiredDescription
namestring-yescountry name (e.g.,Great Britain)
languagestring-yeslanguage name (e.g., English)
domainstring-yeslanguage code ISO 639-1 (e.g., gb)
localestring-yeslocale (e.g., en-GB)
phonePrefixstring-yesphone prefix (e.g., +44)