Skip to content
Comvi

Quick start

View .md

Install one package, render a translated heading and switch its locale. Pick the framework in the header; the tabs follow it.

Terminal
npm install @comvi/react

Or open the React example in StackBlitz to see the switcher, plurals and lazy catalogs running.

The binding depends on @comvi/core, so one install is the whole of it. pnpm, yarn and bun take the same package names.

src/main.tsx
import { createRoot } from 'react-dom/client';
import { createI18n, I18nProvider } from '@comvi/react';
import App from './App';
const i18n = createI18n({
locale: 'en',
fallbackLocale: 'en',
messages: {
en: { greeting: 'Hello, {name}!' },
uk: { greeting: 'Привіт, {name}!' },
},
});
createRoot(document.getElementById('root')!).render(
<I18nProvider i18n={i18n}>
<App />
</I18nProvider>,
);

locale is the language that renders now, fallbackLocale is where t() looks for a key the current locale lacks, and messages is the catalog, one object per locale.

src/App.tsx
import { useI18n } from '@comvi/react';
export default function App() {
const { t, locale, setLocale } = useI18n();
return (
<>
<h1>{t('greeting', { name: 'Alice' })}</h1>
<select value={locale} onChange={(e) => setLocale(e.target.value)}>
<option value="en">English</option>
<option value="uk">Українська</option>
</select>
</>
);
}

t('greeting', { name: 'Alice' }) looks up greeting in the current locale and fills {name} from the second argument. setLocale() switches the locale, and every component that read a translation re-renders with the new text.

Switch the locale and the heading changes; on Vanilla the translated line is in the browser console.