Components and routes
useParla or t
Section titled “useParla or t”Any component below <ParlaProvider> can call useParla:
function Header() { const { t } = useParla([common]); return <h1>{t.common.title()}</h1>;}
function Cart() { const { t } = useParla([checkout]); return <p>{t.checkout.cart.items({ count: 3 })}</p>;}It can also take t as a prop, typed Translations<typeof ns>. A
namespace loads once per locale, however many components ask for it.
Preload in route loaders
Section titled “Preload in route loaders”A child that suspends after its parent starts downloading late: a waterfall. Load a route’s namespaces before it renders:
// React Router, TanStack Router or any loaderexport async function loader() { await parla.load([common, checkout]); return null;}The components’ useParla calls then resolve at once, whatever their lists.
Without a loader, the page’s own useParla lists its children’s namespaces:
function Page() { useParla([common, checkout]); // one parallel load, before the children render return ( <> <Header /> <Cart /> </> );}