nori-ui

useTranslation

Read i18n keys with interpolation and pluralization. Drives every visible string in the library.

View as JSON

The library's i18n primitive. Every visible string in @nori-ui/core is sourced through this hook — overriding a key in your <NoriProvider i18n={…}> rewires every component that uses it.

Usage

import { useTranslation } from '@nori-ui/core/client';
 
function GreetButton({ name }: { name: string }) {
    const { t } = useTranslation();
    return <button type="button">{t('greet.hello', { name, defaultValue: 'Hello, {{name}}' })}</button>;
}

API

Returns

NameTypeDescription
t(key: string, options?: { defaultValue?: string; count?: number; [k: string]: unknown }) => stringResolve a key against the current dictionary. Falls back to defaultValue if the key is missing.
languagestringActive BCP 47 locale (read-only).

Behavior notes

  • Interpolation uses {{name}} syntax — double braces, no spaces.
  • Pluralization follows i18next conventions: count-based suffixes (_zero, _one, _two, _few, _many, _other).
  • defaultValue is required for every call by convention — it documents the fallback inline and keeps your translation files self-describing.
  • Missing keys return defaultValue and emit a dev warning so missing translations are visible in development.

Adding a custom dictionary

import { NoriProvider } from '@nori-ui/core/client';
 
<NoriProvider i18n={{ en: { 'pagination.next': 'More results →' } }}>
    {children}
</NoriProvider>

Keys you don't override fall through to the library default dictionary.

  • Theming — the sibling provider.

On this page

Preview theme