Language switcher

Links to this page in the site's other languages; put it in the header.

When to use it

Sites in more than one language, usually in the header fragment, so visitors move to the same page in their language.

When not to

Sites in one language: it shows nothing there.

Accessibility

Each link is named in its own language and marked with that language, so screen readers pronounce it right; the current language is marked as current.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The language switcher example as the component library shows it in the default theme

Where it is used

The starter sites that use it, each at a page that shows it:

Fields

This component has no fields: it takes what it shows from the site.

Variants

A variant changes how the component looks. Write it in parentheses after the name in the table’s first cell, several separated by commas.

Variant

Write in the first cell

Short codes (EN, PT)

language-switcher (short)

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table:

language-switcher

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "language-switcher",
  "variants": [
    "short"
  ],
  "rows": []
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

language-switcher

The component

language-switcher__item

A part of it

language-switcher__link

A part of it

language-switcher__list

A part of it

language-switcher--short

A variant

The HTML the example above writes, as the component library builds it in the default theme:

html
<div class="text"><h2>Short codes (EN, PT)</h2></div>

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.languages.label

Language

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/language-switcher.js
  • src/components/language-switcher/language-switcher.liquid
  • src/components/language-switcher.client.js

It has a browser script, the .client.js file above. Without it the component still shows all its content; the script only adds behaviour.