Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/formsmd/formsmd/llms.txt

Use this file to discover all available pages before exploring further.

The translate() function returns a localized string from a translations object based on the current localization setting.

Function signature

function translate(
  localization: string,
  translations: TranslationsType
): string

Parameters

localization
string
required
The language code to use for translation. Should match one of the supported language codes (e.g., "en", "es", "fr").
translations
TranslationsType
required
An object containing translations for one or more languages. Each property is a language code with its corresponding translated text.

Returns

string
string
The translated text for the specified localization. If the requested language is not found in the translations object, returns the first available translation.

Usage example

import { translate } from 'forms.md';

const greeting = translate('es', {
  en: 'Hello',
  es: 'Hola',
  fr: 'Bonjour'
});

console.log(greeting); // "Hola"

TranslationsType

The TranslationsType object contains optional properties for each supported language.

Type definition

type TranslationsType = {
  en?: string;  // English
  ar?: string;  // Arabic
  bn?: string;  // Bengali
  de?: string;  // German
  es?: string;  // Spanish
  fr?: string;  // French
  ja?: string;  // Japanese
  pt?: string;  // Portuguese
  zh?: string;  // Chinese
}

Supported languages

Forms.md supports the following 9 languages:
Code: enDefault language for Forms.md. Used as fallback when other languages are unavailable.
{
  en: 'Your text in English'
}

Best practices

Always provide at least an English (en) translation as a fallback. This ensures your content displays even when other languages are unavailable.

Complete example

import { Composer, translate } from 'forms.md';

// Create a multilingual form
const form = new Composer({
  localization: 'es',
  title: translate('es', {
    en: 'Contact Us',
    es: 'Contáctenos',
    fr: 'Contactez-nous',
    de: 'Kontaktieren Sie uns'
  })
});

form.textInput('name', {
  question: translate(form.settings.localization, {
    en: 'What is your name?',
    es: '¿Cuál es tu nombre?',
    fr: 'Quel est votre nom?',
    de: 'Wie ist Ihr Name?'
  }),
  required: true
});