Other Exports
In addition to useTranslation, the @multilocale/react package exports several utility functions.
init
Initialize Multilocale with your project settings. Must be called before using useTranslation.
import { init } from '@multilocale/react'
init({
organizationId: 'your-organization-id',
project: 'your-project-name',
defaultLanguage: 'en', // optional
dictionaries: { en: { ... } }, // optional, pre-loaded translations
})
Parameters
| Property | Type | Required | Description |
|---|---|---|---|
organizationId | string | Yes | Your organization ID from the dashboard |
project | string | Yes | The project name |
defaultLanguage | string | No | Default language code (e.g., 'en') |
dictionaries | Record<string, Record<string, string>> | No | Pre-loaded translation dictionaries |
setDictionaries
Manually set the translation dictionaries at any point.
import { setDictionaries } from '@multilocale/react'
setDictionaries({
en: { greeting: 'Hello' },
es: { greeting: 'Hola' },
})
getDefaultLanguage
Returns the currently configured default language.
import { getDefaultLanguage } from '@multilocale/react'
const lang = getDefaultLanguage() // 'en'
setDefaultLanguage
Update the default language after initialization.
import { setDefaultLanguage } from '@multilocale/react'
setDefaultLanguage('fr')
initMultilocale
Alias for init.
import { initMultilocale } from '@multilocale/react'
initMultilocale({ organizationId: '...', project: '...' })