@npc-enterprises/tongues-nextjs
v1.20.1
Published
Next.js (App Router) client for the Tongues translation platform: formatjs ICU, ETag/SWR, proxy (SPEC §8.1).
Downloads
951
Maintainers
Readme
sdk/nextjs — @npc-enterprises/tongues-nextjs
TypeScript / Next.js App Router SDK (server components + client hooks + route-handler proxy in one install).
Usage
Set TONGUES_API_URL (and TONGUES_API_TOKEN if the API is token-gated) in the server environment.
Server components — translate directly:
import { getTranslations } from '@npc-enterprises/tongues-nextjs/server';
const t = await getTranslations({ namespace: 'shop', locale: 'nl-NL' });
return <h1>{t('greeting', { name })}</h1>;Client components — fetch the bundle on the server, hydrate the provider (no hand-rolled fetch):
import { getBundle } from '@npc-enterprises/tongues-nextjs/server';
import { TonguesProvider, useTranslate } from '@npc-enterprises/tongues-nextjs/client';
// in a server component / layout:
const bundle = await getBundle({ namespace: 'shop', locale: 'nl-NL' });
return <TonguesProvider bundle={bundle}>{children}</TonguesProvider>;
// in a client component:
const t = useTranslate();getBundle returns the ETag-cached { locale, version, schemaVersion, entries }; it throws on a hard
fetch failure with no cached bundle, so catch it if you want to fall back to a static base.
See SPEC §8.1, §14, §15 (golden ICU + contract tests), §20 (schemaVersion handling).
Contract-first from backend/.../openapi.yaml (hand-written client; spec for type-checking in CI).
