githubEdit

Language and Currency Synchronization

VeChainKit supports bidirectional synchronization of language and currency preferences between the kit and host applications. This allows changes made in either the kit's settings or the host app to be reflected in both places.

Overview

The bidirectional sync feature enables:

  • Kit → Host: When users change language or currency in VeChainKit settings, the host app can be notified and update accordingly

  • Host → Kit: When the host app changes language or currency, VeChainKit automatically reflects these changes

Features

Language Synchronization

Language preferences are synchronized between:

  • VeChainKit's language settings (accessible via Account Modal → Settings → General → Language)

  • Host application's i18n instance

  • Browser localStorage (i18nextLng)

Currency Synchronization

Currency preferences are synchronized between:

  • VeChainKit's currency settings (accessible via Account Modal → Settings → General → Currency)

  • Host application's state

  • Browser localStorage (vechain_kit_currency)

Usage

Basic Setup

The bidirectional sync is enabled automatically when you use VeChainKitProvider. You can optionally provide callbacks to be notified of changes:

Reading Current Values

Using Convenience Hooks

The easiest way to access current language and currency values:

Using useVeChainKitConfig Hook

You can also access current values through the config hook:

Changing Values from Host App

You can change language or currency from your host app, and VeChainKit will automatically sync:

Listening to Changes

Use the optional callback props to react to changes made in VeChainKit:

circle-exclamation

API Reference

VeChainKitProvider Props

language?: string

Initial language code (e.g., 'en', 'fr', 'de'). Defaults to 'en'.

defaultCurrency?: CURRENCY

Initial currency code ('usd', 'eur', or 'gbp'). Defaults to 'usd'.

onLanguageChange?: (language: string) => void

Optional callback fired when language is changed in VeChainKit settings.

onCurrencyChange?: (currency: CURRENCY) => void

Optional callback fired when currency is changed in VeChainKit settings.

Hooks

useCurrentLanguage()

Returns the current language and a function to change it.

Returns:

  • currentLanguage: string - Current language code

  • setLanguage: (language: string) => void - Function to change language

useCurrentCurrency()

Returns the current currency and a function to change it.

Returns:

  • currentCurrency: CURRENCY - Current currency code

  • setCurrency: (currency: CURRENCY) => void - Function to change currency

useVeChainKitConfig()

Returns the full VeChainKit configuration including current language and currency.

Returns:

  • currentLanguage: string - Current runtime language value

  • currentCurrency: CURRENCY - Current runtime currency value

  • setLanguage: (language: string) => void - Function to change language

  • setCurrency: (currency: CURRENCY) => void - Function to change currency

  • ... (other config properties)

Storage

Language and currency preferences are persisted in browser localStorage:

  • Language: i18nextLng (managed by react-i18next)

  • Currency: vechain_kit_currency

Changes persist across page reloads and browser sessions.

Notes

  • Use currentLanguage and currentCurrency from useVeChainKitConfig() to get the current runtime values.

  • Changes made in VeChainKit settings automatically update localStorage and trigger callbacks.

  • Changes made via setLanguage() or setCurrency() from the host app automatically sync to VeChainKit.

  • The sync works bidirectionally - changes in either direction are reflected in both places.

Last updated

Was this helpful?