API reference

<I18nProvider>

Top-level provider. Wrap your app once.

PropTypeDefaultDescription
projectKeystringProject API key (starts with bjs_). Mode 2/3.
projectIdstringFor JWT auth (advanced).
apiTokenstringJWT for advanced auth.
preloadedTranslationsRecord<string, Record<string, string>>Bundle translations into your app (Mode 1).
defaultLangstring"en"Initial language code.
apiUrlstring"https://api.bhashajs.com"API base URL (override for self-hosting).
regionstringRegion override: "IN", "BD", "PK", "LK", "NP". Affects currency + Intl locale.
onLanguageChange(lang: string) => voidCallback whenever language changes.

useTranslation()

const {
  t,                  // (key, params?) => string
  currentLang,        // "hi"
  setLang,            // (lang: string) => void
  supportedLangs,     // string[]
  isLoading,          // boolean
  error,              // string | null — surfaces auth/network errors
  formatNumber,       // (value, options?) => string
  formatCurrency,     // (value, options?) => string
  formatDate,         // (date, options?) => string
} = useTranslation();

t(key, params?)

The translation function. Returns the translated string for the current language with fallback chain support.

t("hero.title");                              // simple lookup
t("greeting", { name: "Rohan" });              // interpolation
t("items", { count: 5 });                       // pluralization (uses items_one / items_other)

setLang(lang)

Switch the active language. Triggers font load + RTL switch + re-render.

useLangInfo()

const {
  code,            // "hi"
  name,            // "हिन्दी"
  englishName,     // "Hindi"
  dir,             // "ltr" | "rtl"
  font,            // "Noto Sans Devanagari, sans-serif"
  script,          // "Devanagari"
  defaultRegion,   // "IN"
  intlLocale,      // "hi-IN"
  defaultCurrency, // "INR"
} = useLangInfo();

<LanguageSwitcher />

PropTypeDefault
style"dropdown" | "floating""dropdown"
position"top-right" | "top-left" | "bottom-right" | "bottom-left""top-right"
classNamestring

<Trans />

Component-based translation, useful when wrapping rendered output.

<Trans id="hero.title" />
<Trans id="greeting" params={{ name: "Rohan" }} as="h1" />

Standalone utilities

These don't need React. Import directly.

formatNumber(value, lang, region?, options?)

OptionTypeDescription
useNativeDigitsbooleanRender digits in the native script (१२३ instead of 123).
compactbooleanCompact notation (1.5 लाख, 2 करोड़).

formatCurrency(value, lang, region?, options?)

OptionTypeDescription
currencystringOverride the auto-detected currency (e.g. "USD", "EUR").
display"symbol" | "code" | "name"How to render the currency.
useNativeDigitsbooleanRender digits in the native script.

formatDate(date, lang, region?, options?)

OptionTypeDescription
preset"short" | "medium" | "long" | "full"Default "medium".
useNativeDigitsbooleanRender digits in the native script.

getPluralCategory(count, lang)

Returns "one" or "other" based on the language's CLDR plural rules.

getPluralCategory(0, "hi");   // "one"   (Hindi: 0 is singular)
getPluralCategory(0, "en");   // "other" (English: 0 is plural)
getPluralCategory(1, "ta");   // "one"

getFallbackChain(lang)

Returns the culturally-aware fallback chain for the language.

getFallbackChain("bn");   // ["bn", "hi", "en"]
getFallbackChain("ta");   // ["ta", "en"] (Dravidian — skips Hindi)
getFallbackChain("pa-PK");// ["pa-PK", "ur", "en"]

getLangInfo(lang), LANGUAGES, REGION_OVERRIDES

Read-only access to the language metadata database.