Search documentation

Search all pages, headings and text, in the current package or topic or in all documentation.

Getting started

Receive active-i18n, supply your dictionaries, and translate in a client component.

@workspace/active-i18n 1.1.0Developmentunreleased, in development in Foundationbaseline ce081dc3

  1. Receive the package#

    active-i18n is a product; active-format comes along as its owner. Ask the maintainer of Foundation for a bundle that contains your whole managed set (a bundle without a package you already have would remove it), then follow Receiving packages:

    Terminal
    node tools/rps/rps-apply.mjs plan --bundle <bundle-folder> --developmentnode tools/rps/rps-apply.mjs apply --bundle <bundle-folder> --expect-plan <digest> --development
  2. Declare, install and verify#

    JSON
    {  "dependencies": {    "@workspace/active-i18n": "workspace:*",    "react": "^19.0.0"  }}
    Terminal
    pnpm installnode tools/rps/rps-apply.mjs verify-install --from <app-folder>

    In Next.js, list @workspace/active-i18n and @workspace/active-format in transpilePackages.

  3. Supply your dictionaries#

    A dictionary is a tree per namespace. A key is a dot path whose first segment is the namespace:

    TypeScript
    // The host's resources, for example resources/en/inbox.json:const en = {  inbox: {    greeting: 'Hello {{name}}',    messages: {one: '{{count}} new message', other: '{{count}} new messages'},  },};
  4. Translate#

    Without React, build a translator; in React, mount the provider once and read it with a hook:

    TSX
    import {createTranslateFunction} from '@workspace/active-i18n';import {I18nProvider, useTranslations} from '@workspace/active-i18n/react';
    const t = createTranslateFunction(en, 'en');t('inbox.messages', {count: 2}); // '2 new messages'
    function Greeting() {  const t = useTranslations();  return <p>{t('inbox.greeting', {name: 'Ada'})}</p>;}
    <I18nProvider  locale="en"  translations={en}  supportedLanguages={[{code: 'en', label: 'English'}]}>  <Greeting /></I18nProvider>;

    Interpolation, plurals and a missing keyClient

    Hello Ada

    2 new messages

    inbox.archived

    count = 2

    Missing keys reported: inbox.archived

Next#

This page as Markdown