Switching locale
parla.subscribe(() => render(parla.locale));await parla.switchLocale('it');switchLocale(next) loads every loaded namespace for next, then switches and notifies listeners. The
old text stays until then: no flash. Live, through the React adapter:
switchLocale |
|---|
| Rejects for a locale not in the catalog |
| A failed download rejects and keeps the current locale |
| Two calls in a row: the last one wins |
Namespaces first loaded during the switch are loaded for next too |
<html lang dir>
Section titled “<html lang dir>”import { direction } from '@parlajs/core';
const sync = () => { document.documentElement.lang = parla.locale; document.documentElement.dir = direction(parla.locale);};sync();parla.subscribe(sync);The first locale
Section titled “The first locale”matchLocale picks the best supported locale:
const parla = createParla({ catalog, locale: matchLocale(navigator.languages, catalog.locales, catalog.sourceLocale),});| Requested | Supported | Picks |
|---|---|---|
de-AT |
en, de |
de: same language |
zh-TW |
zh-Hans, zh-Hant |
zh-Hant: the script outranks the region |
it_IT |
en, it |
it: Android’s _ is read as - |
fr |
en, de |
the fallback |
A server-rendered page starts in the locale it rendered, then switches.