DocumentationAccessibility and i18n

Accessibility and i18n

How Media Boxes works with keyboards, screen readers and reduced motion, and how to translate every label, set number formats and run right-to-left grids.

Accessibility is part of the engine, not an add-on. Controls are real buttons and links, focus is always visible, hover effects also work on keyboard focus, and every piece of text the engine writes can be translated.

Keyboard and screen readers #

In the grid #

In the lightbox #

Colour and contrast #

If you change colours, check the contrast yourself: --mb-accent-contrast on top of --mb-accent, --mb-text-muted on your surface colours, and --mb-focus against your page, which must stay clearly visible. See Theming.

Reduced motion #

When a visitor asks their system for reduced motion (prefers-reduced-motion: reduce):

You do not have to do anything for this to work.

Translating the interface #

All text the engine writes comes from the i18n option. Set only the keys you want to change. The rest keep their English defaults.

html
<media-boxes id="galerie" filter="category" search>
  <script type="application/json" data-mb-options>
  {
    "i18n": {
      "all": "Alle",
      "search": "Suchen…",
      "clearSearch": "Suche löschen",
      "loadMore": "Mehr laden",
      "noResults": "Keine Treffer.",
      "showing": "{count} von {total} angezeigt",
      "close": "Schließen",
      "next": "Weiter",
      "previous": "Zurück",
      "counter": "{current} von {total}",
      "open": "{title} öffnen"
    }
  }
  </script>
  <!-- items -->
</media-boxes>
js
grid.options = { i18n: { loadMore: 'Voir plus', close: 'Fermer' } };

These are all the keys and their defaults:

KeyDefault text
all'All'
search'Search…'
clearSearch'Clear search'
sortBy'Sort by'
ascending'Ascending'
descending'Descending'
loadMore'Load more'
loading'Loading…'
noResults'Nothing matches your filters.'
showing'Showing {count} of {total}'
page'Page {n}'
pagination'Pagination'
close'Close'
next'Next'
previous'Previous'
zoomIn'Zoom in'
zoomOut'Zoom out'
play'Start slideshow'
pause'Pause slideshow'
fullscreen'Fullscreen'
exitFullscreen'Exit fullscreen'
download'Download'
share'Share'
thumbnails'Thumbnails'
counter'{current} / {total}'
open'Open {title}'
copied'Link copied'
error'This could not be loaded.'
lightbox'Lightbox'
gallery'{n} photos'
playVideo'Play {title}'
stopVideo'Stop video'

Some strings contain placeholders in braces, which are replaced at run time: {count} and {total} in showing, {n} in page, {current} and {total} in counter, {title} in open and playVideo, and {n} in gallery. Keep them in your translation.

The pagination navigation also reads an optional pagination key (default "Pagination") for its landmark name. It is not in the defaults list, so add it yourself if you translate the page.

Also translate what you write yourself: the group label and all text of each filter, the sort option labels, the search placeholder, and the text of your own toolbar buttons.

Numbers, prices and dates #

For items built from data, the locale and currency options set the number and price format:

js
grid.options = { locale: 'de-DE', currency: 'EUR' }; // 1.299 €

Dates are shown with the browser's own language. If you need a fixed format, write the date yourself into meta.

Set lang on <html> (and on a grid if its language differs) so screen readers pronounce the content correctly.

Right-to-left languages #

Set dir="rtl" on the page or on the grid. The grid reads the computed direction, so items start at the right, the filters and search box flip, and the pagination arrows point the right way.

html
<html lang="ar" dir="rtl">

The lightbox takes its direction from the <html> element, so for an Arabic or Hebrew lightbox set dir="rtl" on <html> and not only on the grid. In an RTL lightbox the arrow keys follow the reading direction: the left arrow goes to the next slide, as the slides run right to left. If you remap keys to next and prev, they swap in the same way. See the RTL demo.