Skip to content

Guides

Internationalization

FormKrafter separates two things most libraries conflate: the content of a form (authored by whoever built it) and the chrome of the builder (the UI your users click through). They are localized independently, and neither ever sniffs the browser language — the host decides, the library follows.

Any label, placeholder, message or option list in a spec may be a plain string or an object keyed by locale:

A localized label
{ "label": { "en": "Full name", "fr": "Nom complet" } }

Pass locale to the renderer to resolve it:

<FkFormRender spec={spec} locale="fr" />

In the builder, pass locales to get an edit-language selector — panel fields then read and write the selected language:

<FkFormBuilder locales={['en', 'fr']} />

The palette, property panel, buttons and brick names are about 90 translation keys. English is built in and French ships in the package:

Before mounting the builder
import { setFkTranslations, frFkTranslations } from '@streamline-pulse/formkrafter-wc'
setFkTranslations(frFkTranslations)

For any other language, pass your own dictionary — it is merged over the built-in English, so a partial translation is valid:

setFkTranslations({
'palette.search': 'Bausteine suchen…',
'panel.validation': 'Validierung',
})

Because nothing is automatic, the choice is explicitly yours — a URL segment, a user preference, a cookie. A typical wiring:

Locale from the route
import { setFkTranslations, frFkTranslations } from '@streamline-pulse/formkrafter-wc'
const locale = useRouteLocale() // your router, your rule
if (locale === 'fr') setFkTranslations(frFkTranslations)
return <FkFormRender spec={spec} locale={locale} />

A project by Streamline Pulse