1. Home
  2. ChevronRightUtils
  3. ChevronRightgetTranslated

getTranslated

Extract translated values from a locale mapping dictionary.

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


ImportLink

import { getTranslated } from 'boltdocs/client'

SignatureLink

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 plain default string.
localestringThe active locale language key (e.g. 'es').
fallbackstringFallback label returned if the current locale matches no key in the dictionary.

Example: Localizing Layout TitlesLink

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 July 27, 2026

Was this page helpful?