-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
33 lines (30 loc) · 789 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {
TranslateContext,
TranslateProvider
} from '@denysvuika/preact-translate';
import { useContext } from 'preact/hooks';
import './style';
function MainComponent() {
const { setLang, t, lang } = useContext(TranslateContext);
return (
<div>
<div>Lang: {lang}</div>
<div>{t('title')}</div>
<div>{t('subtitle')}</div>
<div>Formatted: {t('hello', { name: 'Bob' })}</div>
<div>Fallback: {t('fallback')}</div>
<div>Nested: {t('messages.errors.404')}</div>
<div>
<button onClick={() => setLang('en')}>EN</button>
<button onClick={() => setLang('ua')}>UA</button>
</div>
</div>
);
}
export default function App() {
return (
<TranslateProvider>
<MainComponent />
</TranslateProvider>
);
}