Skip to Content
BBRICKSv0.7.4
DataProvider hooks

useLanguage

The language a component draws in: its own prop first, then the provider's.

import { useLanguage } from '@ergasti/bricks';

Examples

Read the resolved configuration

useBricks() returns what the nearest BricksProvider resolved (the built-in TRNDR default without one); useLanguage() is the language alone, and takes a component's own prop first. The two probes below are under the docs frame's preset and under a plain trndrPreset in Arabic.

Code
import { BricksProvider, trndrPreset, useBricks, useLanguage } from '@ergasti/bricks';

function Probe() {
  const config = useBricks();
  const language = useLanguage();
  return (
    <ul>
      <li>language: <b>{language}</b></li>
      <li>currency: <b>{config.currency.code || '(none)'}</b></li>
      <li>statuses: <b>{Object.keys(config.statuses).length}</b>, tiers: <b>{Object.keys(config.tiers).length}</b></li>
      <li>formatMoney: <b>{config.formatMoney('1234.5', { language })}</b></li>
    </ul>
  );
}

function Config() {
  return (
    <div style={{ display: 'grid', gap: 12 }}>
      <Probe />
      <BricksProvider preset={trndrPreset} language="ar"><Probe /></BricksProvider>
    </div>
  );
}

Signature

function useLanguage(language?: Lang | undefined): Lang

Parameters

Prop

Type

Returns

Lang

BricksProvider · useBricks

Source

src/kit/BricksProvider.tsx (line 55) on GitHub.

On this page