getTranslated
Extract translated values from a locale mapping dictionary.
The getTranslated utility extracts localized strings or pages depending on the active locale code.
Import
import { getTranslated } from 'boltdocs/client'
Signature
function getTranslated(
value: string | Record<string, string> | undefined,
locale: string,
fallback?: string
): string
Parameters
| Name | Type | Description |
|---|---|---|
value | string | Record<string, string> | undefined | A key-value localization map or a plain default string. |
locale | string | The active locale language key (e.g. 'es'). |
fallback | string | Fallback label returned if the current locale matches no key in the dictionary. |
Example: Localizing Layout Titles
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