@akhatmirzo/ui

ScriptProvider

Show content in the script the user picks — Latin or Cyrillic Uzbek, remembered across visits.

Oʻzbekiston boʻylab yetkazib berish

Buyurtmangiz 2–3 kun ichida eshigingizgacha yetkaziladi. Toʻlov — naqd yoki karta orqali.

Import

import { ScriptProvider, ScriptToggle, Translit, useScript } from '@akhatmirzo/ui';

You store text in one script (usually Latin) and each user reads it in the script they prefer. Conversion uses toScript from @akhatmirzo/core. It detects the source script on its own, so text stored in Cyrillic converts to Latin just as well.

PartWhat it does
ScriptProviderHolds the current script (optionally in localStorage)
ScriptToggleA "Lotin | Кирилл" switch built on SegmentedControl
TranslitRenders text in the current script and sets the lang attribute
useScript{ script, setScript, t } for your own components and attributes

When to use

  • Uzbek-language apps — some users prefer reading Cyrillic. You don't have to write the content twice.
  • Headings, buttons and short copy — use Translit or t(). Don't convert user input (names, addresses); keep it as typed.
  • Attributes (placeholder, aria-label, title) — use useScript().t, because Translit renders an element.
  • Not for other languages — this is transliteration between the two Uzbek scripts, not translation.

ScriptToggle

Inside a provider it drives the provider's state. The default labels are "Lotin", "Кирилл" and the group name (aria-label) "Alifbo"; change them with labels. SegmentedControl props (size, fullWidth, disabled …) work too.

Tanlovingiz eslab qolinadi — sahifani yangilab koʻring.

It also works without a provider as a plain controlled component with value and onValueChange.

useScript

t(text) converts text to the current script. Outside a provider script is 'latin' and t returns the text unchanged, so your component never breaks without one.

script: cyrillic

const { script, setScript, t } = useScript();

t('Salom'); // "Салом" when Cyrillic is selected
setScript('cyrillic');

Persistence and SSR

With storageKey, the choice is saved in localStorage under that key and synced across tabs. The server render and the first client render always use defaultScript; the stored value is read after hydration. That means no hydration mismatch in Next.js. If localStorage is blocked (private mode), the choice lives only for the current session.

app/layout.tsx
<ScriptProvider defaultScript="latin" storageKey="script">
  {children}
</ScriptProvider>

Controlled mode: script + onScriptChange (for example, to store the choice in a user profile).

With other components

Inside a provider, RegionSelect shows region names and MoneyInput showWords spells amounts in the current script.

Props

ScriptProvider

PropTypeDefaultDescription
script'latin' | 'cyrillic'—Current script (controlled)
defaultScript'latin' | 'cyrillic''latin'Initial script; used for SSR and the first render
onScriptChange(script: UzScript) => void—Called when the script changes
storageKeystring—Remember the choice in localStorage under this key
childrenReactNode—

ScriptToggle

Accepts SegmentedControl props except value, defaultValue, onValueChange and children.

PropTypeDefaultDescription
value'latin' | 'cyrillic'—Controlled value; defaults to the provider's script
defaultValue'latin' | 'cyrillic''latin'Used when there is neither a provider nor a value
onValueChange(script: UzScript) => void—Called on change (the provider updates too)
labels{ latin?: string; cyrillic?: string; group?: string }{ latin: "Lotin", cyrillic: "Кирилл", group: "Alifbo" }
size'sm' | 'md' | 'lg''md'

Translit

Other HTML attributes are passed to the element.

PropTypeDefaultDescription
childrenrequiredstring—Text to convert (Latin or Cyrillic)
asElementType'span'Element to render
langstring—Defaults to uz-Latn or uz-Cyrl based on the current script

useScript

PropTypeDefaultDescription
script'latin' | 'cyrillic'—Current script
setScript(script: UzScript) => void—Switch the script
t(text: string) => string—Convert text to the current script

Accessibility

  • lang attribute. Translit sets lang="uz-Latn" or lang="uz-Cyrl" on its element, so screen readers pick the right pronunciation and search engines see the script. Without a provider, lang is detected from the text itself. <html lang> is left alone.
  • ScriptToggle is a radiogroup (aria-label "Alifbo") navigated with ←→. The "Кирилл" option carries lang="uz-Cyrl", so it is read correctly in a Latin interface.
  • Focus is kept. Switching scripts only changes text; elements are not re-created.

On this page