import { Suspense, useEffect, useState } from 'react'; import { useTick } from '@wojtekmaj/react-hooks'; import T, { TProvider, useTranslation } from '@wojtekmaj/react-t'; import LocaleOptions from './LocaleOptions.js'; import Options from './Options.js'; import './Test.css'; import { delayedLanguageFiles, languageFiles } from './i18n/index.js'; import type { PassMethod } from './shared/types.js'; function FancyJohn() { const tick = useTick(); const oneTwo = tick % 2 === 0; return ( {oneTwo ? '✨' : '🌟'} John {oneTwo ? '🌟' : '✨'} ); } function TestContent() { const stringOne = useTranslation('Hello world!'); const stringTwo = useTranslation('Hello {name}!', { name: 'John' }); const stringThree = useTranslation('Hello {name} and {other}!', { name: 'John', other: 'Elisabeth', }); const stringFour = useTranslation('Hello {name}! Nice to meet you {name}!', { name: 'John', }); const stringFive = useTranslation('Hello {name}!', { name: }); return (

Using T component

Hello world!

{'Hello {name}!'}

{'Hello {name} and {other}!'}

{'Hello {name}! Nice to meet you {name}!'}

}>{'Hello {name}!'}

Always in Spanish

Hello world!

Using useTranslation hook

{stringOne}

{stringTwo}

{stringThree}

{stringFour}

{stringFive}

); } export default function Test() { const [locale, setLocale] = useState(); const [delay, setDelay] = useState(false); const [suspend, setSuspend] = useState(false); const [passMethod, setPassMethod] = useState('attribute'); useEffect(() => { const html = document.documentElement; if (locale && passMethod === 'attribute') { html.setAttribute('lang', locale); } else { html.removeAttribute('lang'); } }, [locale, passMethod]); return (

react-t test page

Loading…
}>
); }