getTranslated

Extract translated values from a language mapping dictionary.

The getTranslated utility extracts localized strings or pages depending on the active language code.

SignatureLink

ts
function getTranslated(
  value: string | Record<string, string> | undefined,
  locale: string,
  fallback?: string
): string

ParametersLink

NameTypeDescription
valuestring | Record<string, string> | undefinedA key-value localization map or a simple default string.
localestringThe active region language key (e.g., 'es').
fallbackstringFallback label returned if the current region doesn't match any key in the dictionary.

Example: Localizing Layout TitlesLink

tsx
import { getTranslated, useI18n } from 'boltdocs/client'

const headingTranslations = {
  en: 'Welcome to the documentation',
  es: 'Bienvenido a la documentación',
  fr: 'Bienvenue dans la documentation'
}

export function LocalizedBanner() {
  const { currentLocale } = useI18n()

  const bannerText = getTranslated(
    headingTranslations,
    currentLocale || 'en',
    'Welcome'
  )

  return (
    <header className="py-6 border-b">
      <h1 className="text-2xl font-bold">{bannerText}</h1>
    </header>
  )
}
Last updated on October 18, 2026

Was this page helpful?