Portable UI

useTranslation

v1.0.0

Hook to access translations inside a module component. Returns t() for string lookup with {{var}} interpolation.

Import

import { useTranslation } from '@meteorack/modules-sdk-ui/i18n';

How To Use It

  • Call t('key') for simple lookups or t('key', { name: 'World' }) for interpolation.

Works Well With

Methods

locale: string

Current active locale.

t(key: string, vars?: Record<string, string | number>): string

Translate a key with optional interpolation.

availableLocales: string[]

All available locale codes.

Example

bootstrap.php
import { useTranslation } from '@meteorack/modules-sdk-ui/i18n';

function MyComponent() {
  const { t } = useTranslation();
  return <h1>{t('welcome_title', { name: 'World' })}</h1>;
}